如何允许创建配置文件的参数以及设计用户注册

时间:2016-06-10 18:06:36

标签: ruby-on-rails devise associations strong-parameters

我在用户和个人资料模型之间拥有经典的has_one / belongs_to关联,并为用户配置了Accept_nested_attributes。在注册表单中,其中一个输入建立了配置文件模型的用户名属性。此属性已正确保存,但rails服务器会吐出“未允许的参数:profile_attributes”。即使结果中似乎没有任何实际错误,我也想知道为什么我收到此消息并将其删除。

我的registrations_controller.rb

  def new
    build_resource({})
    resource.build_profile
    set_minimum_password_length
    yield resource if block_given?
    respond_with self.resource
  end

  def sign_up_params
    devise_parameter_sanitizer.sanitize(:sign_up)
    params.require(:user).permit(:email, :password, :password_confirmation, profile_attributes: [:username])
  end

他们表单代码的相关部分(如果有意义的话)是:

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= f.input :email, required: true, autofocus: true %>
  <%= f.simple_fields_for :profile do |p| %>
    <%= p.input :username, required: true %>
  <% end %>
  ...

我尝试将profile_attributes: [:username]添加到users_controller.rb中的params.require,并且没有消除错误消息。

0 个答案:

没有答案