I've been working through the Ruby on Rails Tutorial by Michael Hartl. Currently, in order to edit any of the User attributes, the user must confirm their password. Is there any way to update the user attributes without having to do this?
My form looks like this:
<%= form_for @user do |f| %>
<div class="field">
<%= f.label :course1 %><br />
<%= f.text_field :course1 %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>"
and my update definition in users_controller.rb looks like this:
def update
if @user.update_attributes(params[:user])
flash[:success] = "Edit Successful."
redirect_to @user
else
@title = "Edit user"
render 'edit'
end
end
Currently, the update_attributes action fails.
Thanks!
On your User
model, you probably have something along the lines of:
validates_presence_of :password_confirmation
Add an if
clause as follows, that way it only checks for the confirmation when the password is actually being changed:
validates_presence_of :password_confirmation, :if => :password_changed?