我已经获得了订单的表单,用户必须选择一个类别,然后选择关联的产品。正如我希望它是动态的,我写了这个:带导轨的窗体中的表格
_form.html.erb
<%= form_for(@order) do |f| %>
<%= f.collection_select :category_id, @categories_list, :id, :name, :prompt => "Selectionner" %>
<%= render :partial => 'products' %>
<%= f.submit 'Enregistrer', :class=>'button add'%>
<% end %>
_products.html.erb:
<%= form_for(Order.new, :remote => true) do |f| %>
<% if [email protected]? %>
<%= f.label 'Produit :' %><br />
<%= f.select :product_id, @products.collect{ |s| [s.name,s.id]}, :prompt => "Selectionner" %>
<% else %>
<%= f.label 'Produit :' %><br />
<%= f.select :product_id, '' %>
<% end %>
<% end %>
控制器
:
def update_product_select
@products = Product.where(:category_id=>params[:id]).order(:name) unless params[:id].blank?
render :partial => "products", :layout => false, :locals => { :products => @products }
end
对于动态部分,它起作用。 但是,当我点击提交按钮时,产品ID不会被发送!
你能告诉我怎么把动态菜单和表单提交结合起来吗?
谢谢。
我不相信你可以在HTML中嵌套表单:http://stackoverflow.com/questions/379610/can-you-nest-html-forms – Andorbal 2013-02-14 14:37:52
所以,在你看来,对我来说最好的办法是什么在表单中有动态菜单? – eluus 2013-02-14 14:44:54
我认为@ mathiewgagne的questinos是很好的。你试图达到什么样的工作流程? – Andorbal 2013-02-14 14:57:49