收到批量分配警告但不知道为什么

发布于 2024-11-28 18:07:34 字数 947 浏览 0 评论 0原文

我对以下有关批量分配的警告感到非常困惑:

WARNING: Can't mass-assign protected attributes: upload_id

这是我的上传模型:

class Upload < ActiveRecord::Base
    belongs_to :uploadable, :polymorphic => true
    attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
    has_attached_file :photo, :styles => { :thumb => '40x40#', :medium => '150x150>', :large => '300x300>'}

这是我的用户模型

class User < ActiveRecord::Base

  has_one  :upload, :as => :uploadable
  attr_accessible :name, :email, :password, :password_confirmation, :birthdate, :emails, :icon_id 

模型中没有 :upload_id。

在控制器更新操作中:

def update
    @user.upload = Upload.find_by_id(params[:user][:upload_id]) 
    respond_to do |format|
      if  @user.update_attributes(:user)
        format.js
      end
    end
end

任何人都可以告诉我为什么会出现此错误。该应用程序可以运行,但我想解决这个问题。

I am very confused by the following warning about mass assignment:

WARNING: Can't mass-assign protected attributes: upload_id

Here is my uploads model:

class Upload < ActiveRecord::Base
    belongs_to :uploadable, :polymorphic => true
    attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
    has_attached_file :photo, :styles => { :thumb => '40x40#', :medium => '150x150>', :large => '300x300>'}

Here is my user model

class User < ActiveRecord::Base

  has_one  :upload, :as => :uploadable
  attr_accessible :name, :email, :password, :password_confirmation, :birthdate, :emails, :icon_id 

There is no :upload_id in the models.

In the controller update action:

def update
    @user.upload = Upload.find_by_id(params[:user][:upload_id]) 
    respond_to do |format|
      if  @user.update_attributes(:user)
        format.js
      end
    end
end

Can anyone tell why I get this error. The application works but I would like to fix this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

メ斷腸人バ 2024-12-05 18:07:34

在模型中,将 :upload_id 添加到 attr_accessible 输入,如下所示:

attr_accessible :name, :email, ... :emails, :icon_id, :upload_id

如果您希望 :upload_id 嵌套在 下: user 在 params 哈希中,它需要被列为用户模型的可访问属性。

In the model, add :upload_id to the attr_accessible inputs, like so:

attr_accessible :name, :email, ... :emails, :icon_id, :upload_id

If you want the :upload_id to be nested under :user in the params hash, it needs to be listed as an accessible attribute for the user model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文