我在设计的小项目上使用强参数gem
我添加User.rb
了一个locale
专栏。这是我的controllers/users/registrations_controller.rb
文件:
class Users::RegistrationsController < Devise::RegistrationsController
def resource_params
params.require(:user).permit(:username, :email, :password, :password_confirmation, :locale)
end
private :resource_params
def create
#add params[:locale] to resource.locale here
super
end
end
这些是从表单接收的参数:
Parameters: {"authenticity_token"=>"ZyrtToHcwsX3zl2ive93cpYaom6HNGA/jnYcSg7pQUQ=", "user"=>{"username"=>"hyperrjas@hyperrjas.com", "email"=>"email@email.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Create account", "locale"=>"es"}
我想添加到user :locale column
参数params[:locale]
我该怎么做?
谢谢!