注文用のフォームがあり、これを使用して、ユーザーはカテゴリを選択してから関連する製品を選択する必要があります。動的にしたいので、これを書きました:
_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 !@products.blank? %>
<%= 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 が送信されません。
動的メニューとフォーム送信を組み合わせる方法を教えてください。
ありがとう。