我遵循了如何使用嵌套属性为记录添加多个回形针上传的教程,这似乎工作得很好但是我现在遇到了一个问题,我无法编辑任何现有记录或添加任何新记录。但我可以通过编辑表单将照片上传到现有记录。
在编辑或保存新记录时,应用重定向但没有任何字段内容保存,因此新记录将保存所有字段为nil,并且在编辑记录时没有任何更改保存。
场地模型
class Venue < ActiveRecord::Base
attr_accessible :venuephotos_attributes
belongs_to :area
belongs_to :venuetype
has_many :reviews
has_many :venuephotos
accepts_nested_attributes_for :venuephotos, :allow_destroy => true
scope :with_type, lambda { |types|
types.present? ? where(:venuetype_id => types) : scoped }
scope :with_area, lambda { |areas|
areas.present? ? where(:area_id => areas) : scoped }
def to_param
"#{id}-#{name.gsub(/\W/, '-').downcase}"
end
end
如果删除attr_accessible:venuephotos_attributes行,则新页面和编辑页面会再次显示。
感谢您的帮助!
答案 0 :(得分:0)
在教程中注意到attr_accessible还包含所有其他字段名称的名称。我添加了它现在工作正常,但这是最好的做法吗?我是编程的新手,是否存在attr_accessible的一些安全问题?