私はレールに不慣れで、レール3で選択フォームの出力を使用する方法を理解するのに苦労しています。以下は私の選択タグです:
<%= form_for(:order, :url => {:action => 'create_order'}) do |f| %>
<%= select_tag( "experience_id", options_from_collection_for_select(@experiences, :experience_id, :experience_type)) %>
<% frame = frame.id %>
<% material = material.id %>
<%= f.hidden_field :frame_id, :value => frame %>
<%= f.hidden_field :material_id, :value => material %>
<div class="submit-button">
<%= submit_tag("Get Started!") %>
</div>
コンテキストから外れると少し混乱するかもしれませんが、エクスペリエンス ID の値を取得し、それを「作成」のコントローラー メソッドの変数に割り当てる必要があります。これは現在次のようになっています。
def create_order
#need to assign the submitted select_tag value and assign it to @order.experience_id
@order = Order.new(params[:order]).update_attributes(params[:order])
@order_id = Order.last.id
redirect_to(:action => 'drivetrain', :id => @order_id )
end
私がトリガーしたコードエラーに見られるように、エクスペリエンスIDが渡されています。experience_id は :order に関連付けられていませんか?
{"commit"=>"Get Started!",
"authenticity_token"=>"LrE2oOk2AkoUJbddC2crjnA5j4tIdxLGla52LWISx08=",
"utf8"=>"✓",
"order"=>{"material_id"=>"1",
"frame_id"=>"1"},
"experience_id"=>"4"}
助けてくれてありがとう!