I have a User model with name, email, password, and bio.
I want to have two kinds of edit forms. One for editing email, bio and the other for just password.
So my question is really two parts.
A) If the update_attributes fails in update method, how to render the correct page, instead of just edit. This is my current update method.
def update
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated"
sign_in @user
redirect_to @user
else
render 'edit'
end
end
B) How do I have route like /users/1/edit for change_password method? So I want something like /users/1/change_password.
B) match '/users/:id/change_password', to: 'users#change_password' did the job.
redirect_to edit_user_path(@user)Should work.
Also I would change your change_password routes to be like this:
Which is a more Rails-y way of doing things. Then, you can do
redirect_to change_password_user_path(@user)