Rails 3.2.3 を使用していますが、大量割り当てに問題があります。
ホテルモデルとHphotoモデル(ペーパークリップと統合)があります
ほとんどすべてを試しましたが、まだ大量割り当てエラーが発生します。
Can't mass-assign protected attributes: hphoto
ご覧ください。
ホテルモデル
has_many :hphotos, :dependent=>:destroy
accepts_nested_attributes_for <other models>, :hphotos
attr_accessible: <other attributes>, :hphoto_attributes
H写真モデル
belongs_to :hotel
has_attached_file :photo,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename"
attr_accessible :hphoto_attributes
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 2.megabytes
validates_attachment_content_type :photo, :content_type=> ['image/jpeg', 'image/png']
私のホテルコントローラー:
def new
@hotel = Hotel.new
@hotel.hphotos.build
respond_to do |format|
format.html
format.json { render :json => @hotel }
end
end
def create
@hotel = Hotel.new(params[:hotel])
<original scaffold code>
end
ご感想ありがとうございます