F
F
Fahrenhei72016-01-19 15:53:06
HTML
Fahrenhei7, 2016-01-19 15:53:06

rails. update_attributes is not executed, or is it executed, but strange?

Hello. Using devise, I want to update user from my controller. But everything is very strange.
routes.rb

get 'users/:id' => 'users#show', :as => :user
  get 'edit'      => 'users#edit'
  patch "edit" => "users#update"

  devise_for :users, :path => '', controllers: {
    sessions: 'custom_sessions',
    registrations: 'custom_registrations'
  }, :path_names => { :sign_up => 'signup',
                      :sign_out => 'logout',
                      :sign_in => 'login',
                      :edit    => nil }
  resources :notes
  root 'notes#index'

users_controller.rb
def edit
    @user = current_user
  end

  def update
    @user = User.find(current_user.id)
    if @user.update_attributes(user_params)
      flash[:notice] = "Profile successfully updated"
      redirect_to root_path
    else
      render 'edit'
    end
  end

  private

  def user_params
    params[:user].permit(:name)
  end

And the form itself:
-provide(:title, "#{@user.name}")
=form_for @user, url: edit_path, method: :patch do |f|
  =f.text_field :name
  =f.submit "update"

In general, what is happening.
localhost:3000/edit, gives the correct page
kvVoGbM.png
We enter new data into the form, press submit and what happens is what is written in the controller as else, that is, render 'edit', BUT, it renders a new page and shows new data in the title, then -there is locally on edit.html.haml #{@user.name} this has been updated, but not in the database.
T1eDBEt.png
What am I doing wrong?
Here's another screenshot if it helps.
R2ykeKU.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
N. Bekseitov, 2016-01-19
@Fahrenhei7

Most likely a validation error. By default, devise requires you to enter your current password to confirm changes.

F
Fahrenhei7, 2016-01-19
@Fahrenhei7

Thank you all, all rashil! His own forgetfulness played a cruel joke.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question