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])
===
Edit User
<%= form_for(@user) do |f| %>
<% render ‘shared/error_messages’, :object => f.object %>
<%= f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.label :last_name %>
<%= f.text_field :last_name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.submit "Update" %>
<% 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? %>
<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>
<% end %>