Leonel *.* wrote in post #1017341:
> I temporarily solved the username attribute by not letting the user
> update the username. So the validation only works :on => :create
> So username attribute validation problem solved.
>
> Now I got the password validation problem. Ok, it seems the problem was
> kinda of obvious but I couldn't see it.
>
> In user.rb I have this...
> -----------------------------------------
> validates :password,
> :presence => true,
> :length => { :minimum => 6, :maximum => 20, :message => 'should have
> between 6 to 12 characters' },
> :confirmation => true
> ------------------------------------------
>
> but the password attribute doesn't even exist because it's a virtual
> attribute. The real attributes are password_hash and password_salt.
>
> So the Change Password and Password Reset controllers and forms work
> well.
>
> When I go to the Edit User page, user can edit...
> * first name
> * last name
> * email
> * there is NO Password field
>
> PROBLEM: So when the user tries to update his, let's say, first name and
> clicks on Save Changes, I get a password length and password can't be
> blank validation error.
>
Why aren't you doing:
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
===
<h1>Edit User</h1>
<%= form_for(@user) do |f| %>
<% render 'shared/error_messages', :object => f.object %>
<div>
<div><%= f.label :first_name %></div>
<div><%= f.text_field :first_name %></div>
</div>
<div>
<div><%= f.label :last_name %></div>
<div><%= f.text_field :last_name %></div>
</div>
<div>
<div><%= f.label :email %></div>
<div><%= f.text_field :email %></div>
</div>
<div><%= f.submit "Update" %></div>
<% end %>
=======
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Profile Updated"
redirect_to @user
else
@title = 'Edit User'
render 'edit'
end
end
===app/views/shared/_error_messages:
<% if object.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(object.errors.count, 'error') %>
prohibited your account from being created!</h2>
<p>There were problems with the following fields:</p>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.