2

好的,这很奇怪,我基本上有以下课程:

class PriceProfile < ActiveRecord::Base
  has_many :prices
  has_many :price_profile_date_ranges

  attr_accessible :name, :price_profile_date_ranges_attributes
  accepts_nested_attributes_for :price_profile_date_ranges

}

class PriceProfileDateRange < ActiveRecord::Base
  attr_accessible :end_date, :price_profile_id, :start_date, :prices, :prices_attributes
  has_many :prices, :dependent=>:destroy
  belongs_to :price_profile

  accepts_nested_attributes_for :prices
}

class Price < ActiveRecord::Base
  attr_accessible :price_profile_date_range_id, :price_profile_id, :product_id, :value
  belongs_to :price_profile
  belongs_to :price_profile_date_range
  belongs_to :product
}

价格配置文件定义了价格随时间变化的特定产品的定价方案。应用价格的日期范围存储在 price_profile_date_range 表中,最后价格表保存所有价格。我正在使用以下控制器和视图在此处创建表单,以便在创建日期范围时设置价格。基本上,该表格有一个开始和结束日期字段和一个网格,即它将有一个针对所有产品的文本框列表来输入价格。

这是视图:

.row
  .span9
    = simple_form_for(@price_profile_date_range, :class=>'well') do |f|


  .form-inputs
    = f.input :start_date, :required => true, :as => :string, :input_html =>{:class=>'datepicker'}
    = f.input :end_date, :required => true, :as => :string, :input_html =>{:class=>'datepicker'}
    = f.input :price_profile_id, :as=>:hidden
    %table.table.table-bordered.table-condensed.table-striped
      %tr
        %td
        - @products.each do |product|
          %td
            =product[:name]
          %td
            - f.fields_for(:prices) do |price_element|
              = price_element.input :value, :class=>'span1'
              = price_element.input :price_profile_id, :as=>:hidden
              = price_element.input :price_profile_date_range_id, :as=>:hidden
              = price_element.input :product_id, :as=>:hidden
  .form-actions
    = f.button :submit

这不完全是最终形式 - 问题是 f.fields_for 行似乎没有执行。在控制器中,我使用一组价格初始化 @price_profile_date_range 对象。如果我进行加价检查,即使在视图中也会显示所有价格对象,但是 fields_for 根本不执行。我被困在这里真的很糟糕。

4

1 回答 1

3

尝试将其更改-=- 听起来很傻,但也许这就是问题所在。

于 2012-08-22T23:29:22.723 回答