【问题标题】:data not saved in nested table with hidden (array) field passed数据未保存在嵌套表中并传递了隐藏(数组)字段
【发布时间】:2013-12-16 06:01:53
【问题描述】:

当我提交表格时:

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

查看

<% @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

你可以看到我之前关于this的问题。

我正在等待有价值的回复。谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 nested-forms nested-attributes


    【解决方案1】:

    您应该添加您的 Esthour 模型:

    attr_accessible :modul1hours_attributes
    

    【讨论】:

      猜你喜欢
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多