Rails 如何把 select 选择的值通过 button_to 传输给另外的一个 controller 中的 action?

zafu10 · 2012年04月27日 · 最后由 ericguo 回复于 2012年06月29日 · 4772 次阅读

<%= form_tag line_items_path(:product_id => product.id) do %> <%= label(:ammount, "Ammount:") %> <%= select_tag(:ammount, options_for_select([1,2,3,4,5,6,7,8,9,10])) %> <%= submit_tag 'Add to cart' %> <% end %>

希望实现上面代码类似的功能,但是我想要传输的是 ammout 的值给另一个 controller,类似于

<%= button_to 'Add to cart', line_items_path( :quantity => :ammount) %> 该如何实现呢?

貌似不可以,button_to 实际上是封装了 form_tag 的 link_to,所以还是 在 form tag 里面老老实实用 hidden field 吧…

需要 登录 后方可回复, 如果你还没有账号请 注册新账号