Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails——有很多大规模的分配问题_Ruby On Rails_Has Many - Fatal编程技术网

Ruby on rails RubyonRails——有很多大规模的分配问题

Ruby on rails RubyonRails——有很多大规模的分配问题,ruby-on-rails,has-many,Ruby On Rails,Has Many,我使用的是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_acces

我使用的是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
我的酒店管理员:

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
def新建
@新酒店
@hphotos.build酒店
回应待办事项|格式|
format.html
format.json{render:json=>@hotel}
终止
终止
def创建
@hotel=hotel.new(params[:hotel])
终止

感谢您的想法

声明必须使用复数:

attr_accessible: <other attributes>, :hphotos_attributes
attr\u可访问:,:hphotos\u属性
在Rails 3.2.3上,我的erb如下所示:

<%= f.fields_for :hphotos, @hotel.hphotos do |photo_form| %>  
    <%= photo_form.label :size %>  
    <%= photo_form.text_field :size %>  
<% end %>  


当我提交表单时,问题出在哪里。“无法批量分配受保护的属性:hphoto”感谢您提供的
:hphotos_属性
。我缺少复数形式,而且,在我看来,我有
f.fields\u用于:hphoto
,我需要把
:hphoto
。谢谢你的意见。当做
<%= f.fields_for :hphotos, @hotel.hphotos do |photo_form| %>  
    <%= photo_form.label :size %>  
    <%= photo_form.text_field :size %>  
<% end %>