Bebo
Bebo

Reputation: 129

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?

Upvotes: 0

Views: 118

Answers (1)

rubyprince
rubyprince

Reputation: 17793

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].

Upvotes: 1

Related Questions