On Wed, Feb 15, 2012 at 5:36 AM, Ajit Teli <[email protected]> wrote:

> Hi,
>  I am new to Ruby on Rails. I am trying to use 'check_box_tag' to
> delete multiple tags(objects) at a time. I want to store checked tag_ids
> into a hash. And I should be able to delete all checked tags by clicking
> on 'Click Here' link. But it is not storing tag_ids into hash.
>
> I have attached the image file. Please find it. And also help me.
>
> Thanks
>
>
> <%- @tags.each_with_index do |g, i| -%>
>  <% unless g.id.blank? %>
>      <tr <%= 'class="even_row"' if i.even? %>>
>
>          <td><%= check_box_tag 'tag_ids[]', g.tag_id  %></td>
>    <td><%= g.tag.s_tag_id %></td>
>          <td><%= link_to( g.tag.s_uf_name, :controller =>
> "refrigirators", :action => "edit_tag", :id => g.tag_id  ) %></td>
>
>     <% if g.shelf_id.blank? %>
>        <td> <%= "(none)" %> </td>
>     <% else %>
>          <td> <%= g.shelf.shelf_name %> </td>
>     <% end %>
>
>      </tr>
>    <% end %>
>    <%- end -%>
>
> Attachments:
> http://www.ruby-forum.com/attachment/7060/checkboxtag.jpg
>
>
>
Could you please put the code of your "click here"?.
You have a destroy method in your controller, all you have to do is use
that array and destroy each element

def destroy

     params[:tag_ids].each do |t|
        Tag.find(t).destroy
     end
end

that should work, but I'm not sure if you just can do this

         Tag.find(params[:tag_ids]).destroy

I haven't destroy all of them, but it could work


Javier Q.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to