我有一个问题attr_accessible
和attr_accessor
。
当我在模型中使用 attr_accessor 时:
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
attr_accessible :title, :author, :description, :price, :attach
错误:
Server return:
WARNING: Can't mass-assign protected attributes for Product: crop_x, crop_y, crop_w, crop_h
我编辑如下:
attr_accessible :title, :author, :description, :price, :attach
attr_accessible :crop_x, :crop_y, :crop_w, :crop_h
错误:
Server return:
undefined method `crop_x' for #<Product:0x007fe900f88c20>
所以,我同时使用了attr_accessible
和attr_accessor
:
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
attr_accessible :title, :author, :description, :price, :attach
attr_accessible :crop_x, :crop_y, :crop_w, :crop_h
但是服务器永远运行。