设计在Rails上的自定义字段5
问题描述:
我已经安装了设计gem并将字段添加到fullname
和location
数据库的自定义字段。设计在Rails上的自定义字段5
我更新edit
和new
表单页面为:
<%= f.input :fullname, required: true %>
<%= f.input :location %>
但它不保存或更新此字段。
我错过任何控制器?我经历了数十次教程,但无法弄清楚。
我正在使用Rails 5.1.3和Ruby 2.4.0p0。
答
您可以通过在过滤器之前使用configure_permitted_parameters
以“懒惰的方式”执行此操作。
在您的ApplicationController中,添加指定在devise_parameter_sanitizer
中允许使用的密钥的受保护方法。如果正在使用的控制器是设计注册控制器,则添加指向此方法的before_action回调。
在你的情况可能是这样的:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
permit_attrs(%i[fullname location])
end
def permit_attrs(attrs)
%i[sign_up account_update].each do |action|
devise_parameter_sanitizer.permit(action, keys: attrs)
end
end
end