I have a form for users to change their account details, including their
password.
Here’s my form:
First name(s)
<%= text_field ‘user’, ‘first’ %>
Surname
<%= text_field ‘user’, ‘name’ %>
Telephone
<%= text_field ‘user’, ‘tel’ %>
email
<%= text_field ‘user’, ‘email’ %>
<%= text_field 'user', 'login' %>
Choose password:
Confirm password:
and here's my controller method: def update_user @user = User.find(params[:id]) @project = Project.find(params[:project]) @company = Company.find(params[:company]) if @request.post? and @user.update_attributes(params[:user]) User.authenticate(@user.login, @params[:user][:password]) flash[:notice] = 'User was successfully updated' redirect_back_or_default :action => 'index', :project => @project, :company => @company end end It's all working well and the errors are listed if fields don't validate. However, I want the update to be successful if the two password fields are left empty (user doesn't want to change their password). according to the comments in the user model, the method crypt_unless_empty should catch this before update and I presume allow the record through. This isn't working for some reason and I get 3 errors: - Password confirmation can't be blank - Password can't be blank - Password is too short (min is 5 characters)
Does anyone have any suggestions as to why this doesn’t work (and how I
can
get it working)?
Regards
Adam
PS: Has anyone used the login generator in a commercial rails
application?