Ruby on rails 数据未保存在传递了隐藏字段(数组)的嵌套表中
当我提交表格时:Ruby on rails 数据未保存在传递了隐藏字段(数组)的嵌套表中,ruby-on-rails,ruby,ruby-on-rails-3,forms,nested-forms,Ruby On Rails,Ruby,Ruby On Rails 3,Forms,Nested Forms,当我提交表格时: Parameters: {"authenticity_token"=>"LJ/ZME2lHZ7VwCDgPKX6OFe326fXSXo5UB4M0cPwbCE=", "project_id"=>"second", "utf8"=>"✓", "commit"=>"Add Todo", "esthour"=>{"rfp_id"=>"2", "cms_est_hours"=>"", "modul1hours_attributes"=>{
Parameters: {"authenticity_token"=>"LJ/ZME2lHZ7VwCDgPKX6OFe326fXSXo5UB4M0cPwbCE=", "project_id"=>"second", "utf8"=>"✓", "commit"=>"Add Todo", "esthour"=>{"rfp_id"=>"2", "cms_est_hours"=>"", "modul1hours_attributes"=>{"0"=>{"module_est_hours"=>"11", "modul1_id"=>"3"}, "1"=>{"module_est_hours"=>"111", "modul1_id"=>"4"}}, "designpages_est_hours"=>"", "ecommerce_est_hours"=>""}}
型号
class Esthour < ActiveRecord::Base
has_many :modul1hours
accepts_nested_attributes_for :modul1hours
end
class Modul1hour < ActiveRecord::Base
belongs_to :esthour
attr_accessible :module_est_hours,:module_act_hours,:modul1_id,:esthour_id
end
你可以看到我先前关于的问题
我在等待有价值的答复。谢谢。除了您已经发布的
新操作之外,请发布您的创建
操作。def create@project=params[:project\u id]@esthour=esthour.new(params[:esthour])respond| to do | format | if@esthour.save format.html{重定向到project\u rfp\u url(@project,@esthour.rfp_id),:notice=>'hours已成功创建。}format.json{render:json=>@esthour,:status=>:created,:location=>@esthour}else format.html{render:action=>“new”}format.json{render:json=>@esthour.errors,:status=>:unprocessable_entity}结束
是否报告了任何错误。当您检查日志文件时,是否看到正确的插入查询?@Anish请编辑您的帖子,并在其中添加操作代码。@vinodadhikary没有错误,@majioa操作代码已经存在
<% @m1.map(&:id).each do |id|%>
<%= b.fields_for :modul1hours, @esthour.modul1hours.build do |f| %>
<%= f.hidden_field :modul1_id, :value => id %>
<%= f.text_field :module_est_hours, :size => 30 %>
</tr>
<% end %>
<% end %>
def new
@esthour = Esthour.new
@project = params[:project_id]
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @esthour }
end
end