Tuesday, 20 August 2013

Make a form_for add data to existing model (rails)

Make a form_for add data to existing model (rails)

I have a user model with name password and phone_number. On user creation
I ask for email and password but I need a form on another page to add
phone number!
I tried this:
= form_for @user do |f|
= f.label :phone_number
= f.text_field :phone_number
%p.button
= f.submit
Problem with this is that it hits the user update which asks for
password_reset:
users_controller.rb
def update
if current_user
@user = current_user
else
@user = User.find(params[:id])
end
@user.password_hash = nil
if @user.update_attributes(params[:user])
redirect_to @user, :notice => "Password has been changed!"
else
render "edit"
end
end
How could I fix this?

No comments:

Post a Comment