尝试更新用户帐户时设计强参数

时间:2014-09-11 21:10:49

标签: ruby-on-rails devise

我正在尝试从帐户更新页面移动并提交它。我想我在设计和提交方面遇到了问题。我在应用程序控制器中尝试过一些东西,但没有任何乐趣。我也读过了设计文档,但这对我来说也没有用。我得到的错误如下:1错误禁止此用户被保存:当前密码不能为空 当我输入用户当前密码时就是这种情况?我已经包含了终端的错误以及应用程序控制器的代码。

Processing by Devise::RegistrationsController#update as HTML
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"DVVUgIGna8TZwJTBU/ghNT7PTcO/CERC0JXUUQWOW/o=", "user"=>{"name"=>"Emma", "email"=>"n@m.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]", "line1"=>"", "line2"=>"", "town"=>"", "county"=>"", "postcode"=>"", "organization"=>""}, "commit"=>"Update"}
      User Load (0.3ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 21  ORDER BY "users"."id" ASC LIMIT 1
      User Load (0.4ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = ? LIMIT 1  [["id", 21]]
    Unpermitted parameters: email, password, password_confirmation, current_password, organization






  class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

   before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password) }
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :line1, :line2, :town, :county, :postcode)}
  end

 private
  def after_sign_in_path_for(resource)
    edit_user_registration_path(current_user) #basically whichever path you think meets your needs
  end
end

1 个答案:

答案 0 :(得分:1)

使用以下内容进行更新并解决了此问题

devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :line1, :line2, :town, :county, :postcode, :password, :password_confrimation, :current_password)}