【问题标题】:devise not updating user, redirects to '/users' without any error设计不更新用户,重定向到“/用户”没有任何错误
【发布时间】:2020-07-22 12:48:57
【问题描述】:

每当我尝试更新用户时,我都会被重定向到 /users 并填写了编辑表单但没有错误。

Users::RegistrationsController

class Users::RegistrationsController < Devise::RegistrationsController
 before_action :configure_account_update_params, only: [:update]
 def update
    super
 end

 def configure_account_update_params
    devise_parameter_sanitizer.permit(:account_update, keys: [:name,:property,:admin,:phone_number,:organization,:gender,:profile_pic,:birthday])
 end

...

end

Rails 服务器日志

    Started PUT "/users" for ::1 at 2020-07-22 17:55:57 +0500
Processing by Users::RegistrationsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"iqpDtwA8U1jJ10dtaCV/eE0m96KHUa8G7tWrpOLA48AXYnUjT+6M2qwrwncjThvwQnQQycn/dNCWsbnsteJmhA==", "user"=>{"name"=>"Sohail ", "phone_number"=>"(11", "organization"=>"11", "email"=>"user@test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update"}
  User Load (1.6ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 8], ["LIMIT", 1]]
  User Load (1.7ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 8], ["LIMIT", 1]]
  User Exists (1.1ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = $1 AND "users"."id" != $2 LIMIT $3  [["email", "user@test.com"], ["id", 8], ["LIMIT", 1]]
  Rendering users/registrations/edit.html.erb within layouts/application
  Rendered users/registrations/edit.html.erb within layouts/application (3.9ms)
  StripeCustomer Load (4.6ms)  SELECT  "stripe_customers".* FROM "stripe_customers" WHERE "stripe_customers"."user_id" = $1 LIMIT $2  [["user_id", 8], ["LIMIT", 1]]
  Rendered layouts/_header.html.erb (97.4ms)
  Rendered layouts/_footer.html.erb (15.5ms)
Completed 200 OK in 681ms (Views: 310.2ms | ActiveRecord: 9.0ms)

【问题讨论】:

    标签: ruby-on-rails devise ruby-on-rails-5


    【解决方案1】:

    您的参数似乎有些混乱。您在表单上发送嵌套参数,如下所示:

    "user"=>{"name"=>"Sohail ", "phone_number"=>"(11", "organization"=>"11", "email"=>"user@test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update"}
    

    但是,您允许的参数假定您将所有内容都嵌套在 :account_update 键上。

    因此,您可以更改表单上发送的密钥,或使用此消毒剂:

    def configure_account_update_params
      devise_parameter_sanitizer.permit(:account_update, keys: [:name,:property,:admin,:phone_number,:organization,:gender,:profile_pic,:birthday])
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多