Rails Webpacker с Vue, обновление пароля Devise - PullRequest
0 голосов
/ 21 ноября 2019

Мое приложение использует Rails 6 и Vue. Я установил Devise для аутентификации. Я создал users_controller для выполнения crud над пользователями. У меня проблема с обновлением пароля пользователя:

    store:
     async updateUser ({commit}, currentUser) {
        axios.patch('/users/' + currentUser.id, {
        email: currentUser.email, 
        password: currentUser.password
        current_password: currentUser.current_password,

        })
        .then((response) => {
  console.log(response.errors)

        });  
    },

users_controller:

def update
    @user = User.find_by_id(params[:id])
    if @user.update(user_params)
      flash[:success] = 'User was updated!'
    else
        render json: { errors: @user.errors.full_messages.first }
    end
  end

  def user_params
        params.require(:user).permit(:email, :password)
    end

Terminal:

Started PATCH "/users/1" for ::1 at 2019-11-21 15:14:33 +0800
Processing by UsersController#update as HTML
Started PATCH "/users/1" for ::1 at 2019-11-21 15:14:33 +0800
  Parameters: {"email"=>"user@examllple.com", "password"=>"[FILTERED]", "current_password"=>"[FILTERED]", "id"=>"1", "user"=>{"email"=>"user@examllple.com"}}
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
Processing by UsersController#update as HTML
  Company Load (1.9ms)  SELECT "companies".* FROM "companies" WHERE "companies"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Parameters: {"email"=>"user@examllple.com", "password"=>"[FILTERED]", "current_password"=>"[FILTERED]", "id"=>"1", "user"=>{"email"=>"user@examllple.com"}}
  ↳ app/controllers/application_controller.rb:19:in `create_company'
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/users_controller.rb:61:in `update'
  Company Load (0.5ms)  SELECT "companies".* FROM "companies" WHERE "companies"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
No template found for UsersController#update, rendering head :no_content
  ↳ app/controllers/application_controller.rb:19:in `create_company'
Completed 204 No Content in 12ms (ActiveRecord: 2.5ms | Allocations: 8039)

Пароль не сохраняется. Я понимаю, причина в том, что он не шифруется. Как я могу решить проблему?

...