update_attributes does not work in another "update" action

183 views Asked by At

Well, the problem is interesting: I wonder why update_attributes does not work in the update action which I called "update_name". Everytime the action "update_name" called, the flash "not success" is showed. As I see, everything is written correctly, but may be you can advise me what is wrong here?

routes.rb

resources :users do
  member do
    patch :update_name
  end
end

users_controller.rb

def edit
  @user = User.find(params[:id])
end

def update_name
  @user = User.find(params[:id])
  if @user.update_attributes(user_params2)
    flash[:success] = "name updated"
    redirect_to @user
  else
    flash[:danger] = "not success"
    render 'edit'
  end
end

private
  def user_params2
    params.require(:user).permit(:name, :email)
  end

users/edit.html.erb

<%= form_for @user, :url => update_name_user_path(@user) do |f| %>

  <%= f.label :name %>
  <%= f.text_field :name %>

  <%= f.label :email_field %>
  <%= f.text_field :email %>

  <%= f.submit %>
<% end %>
0

There are 0 answers