views:

33

answers:

1

Hi

I want to send multiple ids that selected with checkboxes to the controller in this code :

<% form_for :product do %>
<table border="1px">
    <tr>
        <th>
            Select
        </th>
        <th>
            Image
        </th>
        <th>
            Product Name
        </th>
        <th>
            Product Description
        </th>
        <th>
            Product Price
        </th>
        <th>
            Categories
        </th>
        <th colspan="3">
            Actions
        </th>
    </tr>
    <% @products.each do |p| %>
    <tr>
        <td>
            <%= check_box_tag "product_ids[]", p.id, false, :id => "product_#{p.id}" %>
        </td>
        <td>
            <%= image_tag p.photo.url(:thumb) , :alt => "#{p.name}" %>
        </td>
        <td>
            <%= link_to "#{p.name}" , edit_product_path(p) %>
        </td>
        <td>
            <%=h truncate(p.description.gsub(/<.*?>/,''),:length => 80) %>
        </td>
        <td>
            <%=h p.price %>
        </td>
        <td>
            <% for category in p.categories.find(:all) %>
            <%= link_to "#{category.name}" , category_path(category.id) %>
            <% end %>
        </td>
        <td>
            <%= link_to 'Show' , product_path(p) %>
        </td>
        <td>
            <%= link_to 'Edit', edit_product_path(p) %>
        </td>
        <td>
            <%= link_to 'Remove', product_path(p), :confirm => "Are you really want to delete #{p.name} ?", :method => 'delete' %>
        </td>
        <% end %>
    </tr>
</table>
<div id="products_nav">
    <%= link_to "Add a new Product" , new_product_path %>
    <%= link_to "Add a new Category" , new_category_path %>
    <%= link_to "Category page" , categories_path %>
    <%= link_to "Remove selected products" , delete_selected_products_path , :method => 'delete' %>
</div>
<% end %>

The code is in this line :

<%= link_to "Remove selected products" , delete_selected_products_path , :method => 'delete' %>
A: 

At first glance it looks OK to me, although the "delete_selected_products_path" route is not typical. Do you have a route specifically set up for this?

In any case, you should be able to send this delete request to the usual method and have the controller check the params.

This Railscast may help.

askegg