【发布时间】:2012-07-04 05:02:21
【问题描述】:
我知道为什么批量分配不好背后的所有安全原因,但我无法弄清楚我的应用为什么要尝试进行批量分配。
我只是想创建我的 Section 模型的新记录,我收到“无法批量分配受保护的属性”错误。以下是可能涉及的模型。有人可以向我解释一下这是如何分配的吗?我是 Rails 新手,所以我可能会遗漏一些非常简单的东西。
class Section < ActiveRecord::Base
belongs_to :project
belongs_to :type, :foreign_key => 'type_id', :class_name => 'SectionType'
attr_accessor :order
end
class SectionType < ActiveRecord::Base
attr_accessible :name, :template
end
class Project < ActiveRecord::Base
has_many :sections
attr_accessible :description, :name, :short, :status, :subtitle, :version
def to_param
return name.gsub(/\s+/, '%20')
end
end
任何帮助将不胜感激,我是 Rails 新手,知道这可能是一个简单的问题,但我一直在努力寻找答案,但找不到。
【问题讨论】:
标签: ruby-on-rails-3 mass-assignment