I’m about to finish the final part of my thread messaging system for users. All deletion works great however before I move on to my next feature I’d like to give users the ability to delete selected messages.
Here’s a way I’ve thought of doing it so far.
- Add a check box tag to the each loop that loops through each message.
- Have a “delete selected” link that goes to my messages controller “destroy_selected_messages” action.
What I need to do is some how grab an array of all the selected messages id’s. Then pass it to the path as an argument. The delete all links path.
<%= link_to 'Delete Selected', messages_destroy_selected_messages_path(ARRAY_WITH_IDS), :method => :delete, :confirm => "Are you sure?" if @current_thread_messages.any? %>
This delete selected link won’t be part of the loop because I don’t want it showing for every message but at the top of the thread instead.
-
I need to figure out how to pass the array with all the selected messages ideas into that argument. How do I get them from the each loop without going into my messages helper and writing some funky method.?
-
I have the checkbox tag e.g. check_box_tag … how do I setup an empty array and then so I can pass in the messages id? e.g.:
<%= check_box_tag ……., :value => message.id &>
Help would be appreciated. I looked at an old screencast in railscasts but it’s from 2007 I think.
Kind regards
name="message_ids[]"for multi select inputs. It will get passed as an array through HTTP server to yourparams[:message_ids].<%= check_box_tag "message_ids[]", :value => message.id %>should suffice.params[:message_ids]and look it up, it should be an Array.