How to params[] value to a user-defined action
I have a form named purchase_products.html.erb
<%= form_for (:purchase) do |f| %>
<% for product in @purchase %>
<%= check_box_tag "product_ids[]", product.id %>
<%= product.product_name %> |
<%= product.description %> |
<%= product.link %> |
<%= link_to开发者_运维百科 'Show', product_path(product) %><br/>
<% end %>
<%= f.submit "Purchase" %>
<%= link_to 'Home', :start %>
<% end -%>
Here when I click the submit button I want to send all selected checkboxes values to a action 'my_purchase' in purchase controller.
How do i redirect my button to call my user defined method?
and how can I do to retrieve which checkboxes are selected?
Add url params to form_for
. See form_for API
<%= form_for(:purchase, :url => {:action => :user_defined_method}) do |f| %>
You can access the checkboxes as an array of product ids in the method as params[:product_ids]
.
精彩评论