我有一个方法在我的控制器中创建一个关联记录:
def updating_rating
rr = ProductRecommendation.new(:rating_id => rating_set.id, :recommendation_id => r.id)
rr.save!
end
我的路由设置为:
match "/recommendations/updating_rating" => "recommendation#updating_rating", :as => 'update'
在我看来,我有:
<div>
<%= form_tag(update_url, :method => :post) do %>
<%= radio_button_tag(:rating_id, '1', :recommendation_id => rec.recommendation.id) %>
<%= radio_button_tag(:rating_id, '2', :recommendation_id => rec.recommendation.id) %>
<%= radio_button_tag(:rating_id, '3', :recommendation_id => rec.recommendation.id) %>
<% end %>
</div>
这只传递rating_id作为一个值。我如何将rating_id +推荐_id传递给控制器方法。
您可以添加一个隐藏字段:
<%= hidden_field_tag :recommendation_id => rec.recommendation.id %>
然后在控制器中获取:recommendation_id
,例如:
params[:recommendation_id]