deviseのページで推奨される手順に従ってユーザ情報を更新できませんでした。フォームのUpdateボタンをクリックすると、何も更新せずにuser/showにリダイレクトされます。コンソールのログには、私のカスタムRegistrationControllerのupdate_resource
アクションの代わりにRegistrationsController#update
アクションが呼び出されたことが示されています。Railsが更新できませんでしたユーザモデルフィールド
ログ:
開始PATCH HTML パラメータとしてRegistrationsController#更新により、2016年12月11日18時34分51秒0200 処理で127.0.0.1のための "/ユーザ":{ "UTF8" => "✓"、 "authenticity_token" => "5vqLuQKyuJIoCx0mYfBUhIQmvS0Il5jy + ty1f2XDsehJM4i3M8mMPK5tdPpVQ6MFHIj05ZcRKO7rhlxroM75pQ =="、 "ユーザー" => { "FIRST_NAME" => "Birhanu"、 "LAST_NAME" => "Hailemariam2"、 "電子メール" => "birhanuh4 「@」、「コミット」=>「ユーザーを更新する」)を入力すると、「@ gmail.com」、「パスワード」=>「[FILTERED]」、「password_confirmation」=>「FILTERED」、「current_password」=>「[FILTERED] "id" = $ 1 ORDER BY "users"。 "id" ASC LIMIT 1 [["" id "、" "subdomain" = $ 1 LIMIT 1 [["subdomain"、 "subdomain"、 "subdomain"、 "サブドメイン" "test3"]] ユーザー負荷(0.4ms)SELECT "ユーザー" * FROM "users" WHERE "users"。 "id" = $ 1 LIMIT 1 [["id"、1]] (0.3ms)BEGIN (0.7ms)、 "ユーザー" (0.3ms)FROM SELECT COUNT(*)を が120msの中で発見302を完了http://test3.lvh.me:3000/users/1 にリダイレクトROLLBACK:
がGET開始(ActiveRecordの4.5ms) "/ユーザ/ 1" のための127.0.0.1 at 2016-12-11 18:34:51 +0200
ビュー/考案/登録/ edit.slim
= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f|
= f.input :first_name, autofocus: true
= f.input :last_name, autofocus: true
= f.input :email, autofocus: true
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
div
|Currently waiting confirmation for: = resource.unconfirmed_email
.form-actions.col-sm-offset-3.m-b-xs
i
|(leave blank if you don't want to change it)
= f.input :password, autocomplete: "off"
= f.input :password_confirmation, autocomplete: "off"
.form-actions.col-sm-offset-3.m-b-xs
i
|(we need your current password to confirm your changes)
= f.input :current_password, autocomplete: "off"
.form-actions.form.col-sm-offset-3
=> link_to I18n.t('button.cancel'), :back, class: 'btn btn-primary btn-outline'
= f.button :submit, class: 'btn btn-primary'
コントローラ/ registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
protected
def update_resource(resource, user_params)
resource.update_with_password(user_params)
end
def after_update_path_for(resource)
current_account
end
end
コントローラ/ application_controller.rb
class ApplicationController < ActionController::Base
.
.
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:accept_invitation, keys: [:first_name, :last_name])
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :email, :password, :password_confirmation,
:current_password])
end
.
.
end
経路:
devise_for :users, controllers: { registrations: 'registrations' }
あなたのルートを更新して、デバイス登録コントローラをオーバーライドしましたか? –
はい、私は顧客登録コントローラへのルートを設定しました。 –
は、新しいパスワードを与えていないという問題ですか? – MZaragoza