0

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

ご感想ありがとうございます

4

1 に答える 1

0

ステートメントでは複数形を使用する必要があります。

attr_accessible: <other attributes>, :hphotos_attributes

Rails 3.2.3 では、私の erb は次のようになります。

<%= f.fields_for :hphotos, @hotel.hphotos do |photo_form| %>  
    <%= photo_form.label :size %>  
    <%= photo_form.text_field :size %>  
<% end %>  
于 2012-05-09T17:02:21.900 に答える