我将Rails 3.2应用更新为强参数(第一天使用它仍然是grokkin)。我为has_one:profile的用户收到以下错误。
用户类(简化形式)如下所示:
class User < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
has_one :profile
accepts_nested_attributes_for :profile
attr_accessible :profile_attributes # this is the line in question
在我的更新方法中,我有:
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(user_params)
flash[:notice] = "This was updated"
#format.html { redirect_to user_home_path, notice: 'User was successfully updated.' }
format.json { head :ok }
end
end
end
private
def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation, profile_attributes: [:name, :about_me, :picture])
end
以上只有在我离开attr_accessible:profile_attributes时才有效。我用
更新了我的application.rbconfig.active_record.whitelist_attributes = false
如果删除attr_accessible:profile_attributes,我会收到以下错误:
WARNING: Can't mass-assign protected attributes: profile_attributes
我的印象是我的attr_accessible消失了。为什么我仍然收到此警告,如何解决?