我第一次使用nested_form gem而且我可能因为资产管道问题而陷入奇怪的问题。这是我的applicatiion.js.coffee文件
#= require jquery
#= require pace
#= require jquery_ujs
#= require jquery-ui-1.10.3.custom.min
#= require jquery-1.10.2.min.js
#= require jquery.ui.touch-punch.min
#= require bootstrap-select
#= require bootstrap-switch
#= require bootstrap-typeahead
#= require flatui-checkbox
#= require flatui-radio
#= require jquery.tagsinput
#= require jquery.placeholder
#= require underscore
#= require backbone
#= require twitter/bootstrap
#= require bootstrap-switch
#= require flatui-checkbox
#= require share
#= require restaurant
#= require jquery.ui.core.min
#= require jquery.ui.position.min
#= require jquery.ui.tabs.min
#= require jquery.ui.timepicker
#= require jquery.ui.widget.min
#= require jquery.remotipart
#= require deal
#= require dashboard
#= require bootstrap-datetimepicker
#= require flippant.min
#= require bootstrap.min
#= require bootstrap-select
#= require bootstrap.js
#= require bootstrap-editable
#= require bootstrap-switch
#= require flatui-checkbox
#= require flatui-radio.js
#= require flatui-fileinput
#= require holder.js
#= require html5shiv
#= require icon-font-ie7
#= require jquery.placeholder.js
#= require jquery.tagsinput.js
#= require jquery.ui.touch-punch.min
#= require jquery-1.8.3.min.js
#= require jquery-2.0.3.min.js
#= require respond.min
#= require typeahead
#= require vex.combined.min
#= require client
#= require jquery_nested_form
window.Views = {}
window.Routers = {}
这些是我的模特
class MenuItem < ActiveRecord::Base
belongs_to :menu
has_many :deal_items
has_many :item_prices, :dependent => :destroy
has_many :swap_items
has_many :required_options
accepts_nested_attributes_for :item_prices, :reject_if => lambda { |a| a[:price].blank? }, :allow_destroy => true
accepts_nested_attributes_for :required_options, :reject_if => lambda { |a| a[:question].blank? }, :allow_destroy => true
belongs_to :section
validates :item_prices, :presence => true
has_attached_file :photo, :styles => {:small => '50x50#', :large => '100x100#', :medium=>"80x80#"},
:default_url => '/assets/images/missing_:style.png'
attr_accessible :name, :price, :title, :description, :photo, :options, :section_id
end
class RequiredOption < ActiveRecord::Base
belongs_to :menu_item
has_many :options
accepts_nested_attributes_for :options, :reject_if => lambda { |a| a[:choice].blank? }, :allow_destroy => true
attr_accessible :question, :menu_item_id
end
class ItemPrice < ActiveRecord::Base
belongs_to :menu_item
has_many :deal_items
attr_accessible :size, :price, :menu_item_id
end
我的控制器是
def new
@section = Section.find(params["section_id"])
@menu = @section.menu
@item = @section.menu_items.build
item_price = @item.item_prices.build
required_option = @item.required_options.build
option = required_option.options.build
end
视图看起来像
<%= nested_form_for @item, :url=> section_menu_items_create_path(@section, @item), method: :post, class: "js_menu_form", :multipart => true, :role=>"form" do |f| %>
<%= f.fields_for :item_prices do |price| %>
<%= price.select :size, options_for_select(["Regular Size", "Small Size","Large Size","Extra Large Size"]),{},:class=>"form-control" %>
<%= price.text_field :price, :class=>"form-control ", :placeholder=>"Enter price" %>
<% end %>
<p><%= f.link_to_add "Add an item price", :item_prices %></p>
<%= f.fields_for :required_options do |r_op| %>
<%= r_op.text_field :question, :class=>"form-control", :placeholder=>"Enter a question for this option" %>
<%= r_op.fields_for :options do |op| %>
<%= op.text_field :choice, :class=>"form-control",:size=>5, :placeholder=>"Enter choice" %>
<%= op.link_to_remove "", :class=>"glyphicon glyphicon-trash", :title=> "remove choice" %>
<% end %>
<% end %>
然而它在我的本地机器上工作正常,但在heroku link_to_add和link_to_remove没有工作没有任何反应当我点击它们没有生成新的表单字段或remvoed我缺少什么。?