我正在使用Devise 4.1.1,并且我已经在用户的个人资料页面中添加了相当多的字段,他/她可以更新。但是,这一个字段pure_veg
没有更新,并且是boolean类型的唯一字段。
这是我的application_controller,我允许使用params -
before_action :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
added_attrs = [:remember_me, :first_name, :last_name, :email, :phone_no, :date_of_birth, :sex, :marital_status, :allergy, :password, :password_confirmation, :current_password, :address_city, :pure_veg]
devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
devise_parameter_sanitizer.permit :account_update, keys: added_attrs
end
我还将用户控制器中的参数列入白名单 -
def secure_params
params.require(:user).permit( :first_name,
:last_name,
:date_of_birth,
:age,
:sex,
:pure_veg,
:marital_status,
:address_door_no_and_street,
:address_city,
:address_state,
:address_landmark,
:height,
:weight,
:hip_size,
:waist_size,
:user_type,
:status,
:subscription,
:allergy,
:bmi,
:whr,
:directions,
:phone_no)
end
最后,这是注册/编辑表格 -
= simple_form_for resource, as: resource_name, url: registration_path(resource_name), \
html: { method: :put, novalidate: false, class: "form-horizontal col-xs-12 col-md-6 col-md-offset-3" } do |f| \
#= f.error_notification
= f.form_group :first_name do |f|
= f.label :first_name, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :first_name, required: true, autofocus: true, class: "form-control"
= f.error_messages
= f.form_group :last_name do |f|
= f.label :last_name, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :last_name, required: true, autofocus: true, class: "form-control"
= f.error_messages
= f.form_group :email do |f|
= f.label :email, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.email_field :email, required: true, autofocus: true, class: "form-control"
= f.error_messages
= f.form_group :phone_no do |f|
= f.label :phone_number, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :phone_no, required: true, autofocus: true, class: "form-control"
= f.error_messages
= f.form_group :date_of_birth do |f|
= f.label :date_of_birth, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :date_of_birth, as: :string, input_html: {class: 'datepicker'},
placeholder: "Date of Birth", class: "form-control", value: f.object.date_of_birth_before_type_cast.try(:strftime,"%Y/%m/%d"),
label: false, start_year: Date.today.year - 110, end_year: Date.today.year, required: true, autofocus: true
= f.error_messages
= f.form_group :pure_veg do |f|
= f.label :pure_veg, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :pure_veg, class: "form-control"
= f.error_messages
= f.form_group :sex do |f|
= f.label :sex, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :sex, class: 'form-control', as: :select, collection: {Male: 0, Female: 1}, label: false, selected: current_user.sex_before_type_cast,
required: true, autofocus: true
= f.error_messages
= f.form_group :marital_status do |f|
= f.label :marital_status, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :marital_status, class: "form-control", collection: {Single: 0, Married: 1, Divorced: 2, Widowed: 3},
label: false, selected: current_user.marital_status_before_type_cast
= f.error_messages
= f.form_group :allergy do |f|
= f.label :allergy, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.text_area :allergy, class: "form-control"
= f.error_messages
= f.form_group :password do |f|
= f.label :password, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :password, class: "form-control"
= f.error_messages
.help-inline
| Leave it blank if you dont want to change it.
= f.form_group :password_confirmation do |f|
= f.label :password_confirmation, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :password_confirmation, class: "form-control"
= f.error_messages
= f.form_group :current_password do |f|
= f.label :current_password, class: "col-xs-2 col-sm-4 col-md-4 control-label"
.col-sm-7
= f.input :current_password, class: "form-control", required: true
= f.error_messages
.help-inline
| We need your current password to confirm your changes.
.form-actions.col-sm-offset-2.mb40
= f.submit "Update", class: 'btn btn-primary'
params也在用户对象中完美呈现。
我做错了什么?其他字段甚至更新。