我遇到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
但服务器永远运行。
答案 0 :(得分:0)
attr_accessor为属性提供setter和getter方法。 attr_accessible表示该属性可以进行质量分配。