即使我在我的 "permit" 语句中包含字段,也得到 "Unpermitted parameter: address"

Getting "Unpermitted parameter: address" even though I included field in my "permit" statement

我正在使用 Rails 4.2.3。我的 user_controller.rb 里有这个……

  def update
    @user = current_user
    if @user.update_attributes(user_params)
      flash[:success] = "Profile updated"
      redirect_to url_for(:controller => 'races', :action => 'index') and return
    else
      render 'edit'
    end
  end

  private

    def user_params
      params.require(:user).permit(:first_name, :last_name, :dob, :address, :automatic_import)
    end

当我的参数提交到“更新”时,

Processing by UsersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"bz24jRzK5qVWolW0oBoQbniiaQi96MeFFmzNjB4kCr0ifUYSsitvQIyod5AWDJd4KS3lrt3mzLiG8F9ef3aJkg==", "user"=>{"first_name"=>"Anthony", "last_name"=>"Alvarado", "dob(2i)"=>"1", "dob(3i)"=>"14", "dob(1i)"=>"1908", "address"=>{"city"=>"chicago"}, "automatic_import"=>"0"}, "state"=>"CT", "country"=>{"country"=>"233"}, "commit"=>"Save", "id"=>"13"}
Unpermitted parameter: address

为什么我在上面的“require”语句中包含了这个不允许的参数消息?我什至在我的 app/models/user.rb 文件中有这个……

class User < ActiveRecord::Base
  …
  belongs_to :address

有 2 个问题相互关联。 (我的假设是用户有一个地址,而不是地址有一个用户。)模型关系应该是:

class User < ActiveRecord::Base
  …
  has_one :address
  accepts_nested_attributes_for :address

地址模型:

class Address < ActiveRecord::Base
  …
  belongs_to :user

这应该可以消除地址的不允许的参数错误。