通过rails单选按钮传递多个值

时间:2013-01-17 00:38:34

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-3.2

我的控制器中有一个创建关联记录的方法:

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和recommendation_id传递给我的控制器方法。

1 个答案:

答案 0 :(得分:2)

您可以添加隐藏字段:

<%= hidden_field_tag :recommendation_id => rec.recommendation.id %>

然后使用以下内容获取控制器中的:recommendation_id

params[:recommendation_id]