I have build a contacts page which displays a number of contacts. I have attached a check_box_tag with each row of these. And then a button to delete those selected. But it is not working. Following is the code snipet, _contact.html.erb> <% @contacts.each do |contact| %> > <tr class=''contactrow'' id=''contact-<%=contact.id%>''> > <td ><%= check_box_tag "contact_ids[]", contact.id %> </td> > <td><%= contact.name %></td> > <td><%= contact.phone %></td> > <td><%= contact.mailid %></td> > <td><%= contact.age %></td> > <td><%= link_to ''Show'', > contact, > :remote=>true > %></td> > <td><%= link_to ''Edit'', > edit_contact_path(contact), > :remote => true%></td> > <td><%= link_to ''Destroy'', > contact, > :method => :delete, > :data => { :confirm => ''Are you sure?'' }, > :remote => true %></td> > <td><%= link_to ''Send Mail'', > {:action => "createmail", :id => contact.id}, > :remote => true %></td> > </tr> > <% end %>> <%= link_to ''Destroy Selected'',{:action => ''destroySelected'',>:id => ''contact_ids''},>:remote => true%>>In Contacts_controller def destroySelected> Contact.delete_all(:id => params[:contact_ids]) > respond_to do |format| > format.html {redirect_to contacts_url} > format.js > end > end >but my development log says no value has been recieved in "id". Where am I doing wrong? Can anyone help. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/eI8HiQZc0fcJ. For more options, visit https://groups.google.com/groups/opt_out.
On Thu, Jul 19, 2012 at 12:37 AM, Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> But it is not working.A useless statement. What does that mean?> but my development log says no value has been recieved in "id". > > Where am I doing wrong?Post the lines from your log showing the request being submitted and the *actual* error message. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
This is what I am receiving in the log, Started GET "/destroy_selected?id=contact_ids" for 127.0.0.1 at Fri Jul 20 14:32:34 +0530 2012 Processing by ContactsController#destroySelected as JS Parameters: {"id"=>"contact_ids"} SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL Rendered contacts/destroySelected.js.erb (0.0ms) Completed 200 OK in 2ms (Views: 1.2ms | ActiveRecord: 0.1ms) On Thursday, 19 July 2012 19:57:39 UTC+5:30, Hassan Schroeder wrote:> > On Thu, Jul 19, 2012 at 12:37 AM, Sumit Srivastava > <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > But it is not working. > > A useless statement. What does that mean? > > > but my development log says no value has been recieved in "id". > > > > Where am I doing wrong? > > Post the lines from your log showing the request being submitted and > the *actual* error message. > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://about.me/hassanschroeder > twitter: @hassan >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/t8REYql61LgJ. For more options, visit https://groups.google.com/groups/opt_out.
On Fri, Jul 20, 2012 at 2:11 AM, Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Started GET "/destroy_selected?id=contact_ids" for 127.0.0.1 at Fri Jul 20 > 14:32:34 +0530 2012 > Processing by ContactsController#destroySelected as JS > Parameters: {"id"=>"contact_ids"} > SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULLSo that tells you what''s wrong with your form, eh? :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
I am aware of that. But I am not able to figure out the way I should pass the parameters. I need help with that. On Friday, 20 July 2012 19:28:19 UTC+5:30, Hassan Schroeder wrote:> > On Fri, Jul 20, 2012 at 2:11 AM, Sumit Srivastava > <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Started GET "/destroy_selected?id=contact_ids" for 127.0.0.1 at Fri Jul > 20 > > 14:32:34 +0530 2012 > > Processing by ContactsController#destroySelected as JS > > Parameters: {"id"=>"contact_ids"} > > SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL > > So that tells you what''s wrong with your form, eh? :-) > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://about.me/hassanschroeder > twitter: @hassan >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DWnPNOCF_jEJ. For more options, visit https://groups.google.com/groups/opt_out.
Carlos Eduardo Ribeiro
2012-Jul-20 18:12 UTC
Re: Deleting multiple contacts using check_box_tag
this works fine for me: http://www.skuunk.com/2008/05/checkbox-arrays-in-rails.html :) 2012/7/20 Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> I am aware of that. But I am not able to figure out the way I should pass > the parameters. I need help with that. > > > On Friday, 20 July 2012 19:28:19 UTC+5:30, Hassan Schroeder wrote: >> >> On Fri, Jul 20, 2012 at 2:11 AM, Sumit Srivastava >> <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org**> wrote: >> >> > Started GET "/destroy_selected?id=contact_**ids" for 127.0.0.1 at Fri >> Jul 20 >> > 14:32:34 +0530 2012 >> > Processing by ContactsController#**destroySelected as JS >> > Parameters: {"id"=>"contact_ids"} >> > SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL >> >> So that tells you what''s wrong with your form, eh? :-) >> >> -- >> Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >> http://about.me/**hassanschroeder <http://about.me/hassanschroeder> >> twitter: @hassan >> > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/DWnPNOCF_jEJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Fri, Jul 20, 2012 at 10:43 AM, Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am aware of that. But I am not able to figure out the way I should pass > the parameters.First, you should strongly consider the wisdom of having a GET request deleting any resource, let alone multiple ones :-)>> > Started GET "/destroy_selected?id=contact_ids" for 127.0.0.1 at Fri JulThen I would look at my form and determine whether all the check boxes are correct. Then write some unobtrusive JS to collect those contact ids into an array. Then you can have the JS submit that array to your controller method (NOT using GET!) , which will have to be rewritten to *accept* an array. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Hi, Still nothing has changed. The log shows parameters being passed as, Parameters: {"contact_ids"=>"contact_ids[]"}>Complete log is Started GET "/destroy_selected?contact_ids=contact_ids%5B%5D" for 127.0.0.1> at Mon Jul 23 14:56:04 +0530 2012 > Processing by ContactsController#destroySelected as JS > Parameters: {"contact_ids"=>"contact_ids[]"} > SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL > Redirected to http://localhost:3000/contacts > Completed 302 Found in 1ms (ActiveRecord: 0.1ms) >Regards Sumit Srivastava The power of imagination makes us infinite... On 20 July 2012 23:42, Carlos Eduardo Ribeiro <duduribeiro.gba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> this works fine for me: > http://www.skuunk.com/2008/05/checkbox-arrays-in-rails.html > :) > > > 2012/7/20 Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> I am aware of that. But I am not able to figure out the way I should pass >> the parameters. I need help with that. >> >> >> On Friday, 20 July 2012 19:28:19 UTC+5:30, Hassan Schroeder wrote: >>> >>> On Fri, Jul 20, 2012 at 2:11 AM, Sumit Srivastava >>> <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org**> wrote: >>> >>> > Started GET "/destroy_selected?id=contact_**ids" for 127.0.0.1 at Fri >>> Jul 20 >>> > 14:32:34 +0530 2012 >>> > Processing by ContactsController#**destroySelected as JS >>> > Parameters: {"id"=>"contact_ids"} >>> > SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL >>> >>> So that tells you what''s wrong with your form, eh? :-) >>> >>> -- >>> Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >>> http://about.me/**hassanschroeder <http://about.me/hassanschroeder> >>> twitter: @hassan >>> >> -- >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/DWnPNOCF_jEJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
This is my code for the button to submit this delete request, <%= link_to ''Destroy Selected'',> {:action => ''destroySelected'', > :contact_ids => ''contact_ids[]''}, > :remote => true%> >Where destroySelected is the action in controller to delete these. Code for the destroySelected action is, def destroySelected> Contact.delete_all(:id => params[:id]) > respond_to do |format| > format.html {redirect_to contacts_url} > #format.js > end > end >Regards Sumit Srivastava The power of imagination makes us infinite... On 23 July 2012 14:56, sumit srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi, > > Still nothing has changed. The log shows parameters being passed as, > > Parameters: {"contact_ids"=>"contact_ids[]"} >> > > Complete log is > > Started GET "/destroy_selected?contact_ids=contact_ids%5B%5D" for >> 127.0.0.1 at Mon Jul 23 14:56:04 +0530 2012 >> >> Processing by ContactsController#destroySelected as JS >> Parameters: {"contact_ids"=>"contact_ids[]"} >> >> SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL >> Redirected to http://localhost:3000/contacts >> Completed 302 Found in 1ms (ActiveRecord: 0.1ms) >> > > Regards > Sumit Srivastava > > The power of imagination makes us infinite... > > > > On 20 July 2012 23:42, Carlos Eduardo Ribeiro <duduribeiro.gba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> this works fine for me: >> http://www.skuunk.com/2008/05/checkbox-arrays-in-rails.html >> :) >> >> >> 2012/7/20 Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> >>> I am aware of that. But I am not able to figure out the way I should >>> pass the parameters. I need help with that. >>> >>> >>> On Friday, 20 July 2012 19:28:19 UTC+5:30, Hassan Schroeder wrote: >>>> >>>> On Fri, Jul 20, 2012 at 2:11 AM, Sumit Srivastava >>>> <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org**> wrote: >>>> >>>> > Started GET "/destroy_selected?id=contact_**ids" for 127.0.0.1 at >>>> Fri Jul 20 >>>> > 14:32:34 +0530 2012 >>>> > Processing by ContactsController#**destroySelected as JS >>>> > Parameters: {"id"=>"contact_ids"} >>>> > SQL (0.1ms) DELETE FROM "contacts" WHERE "contacts"."id" IS NULL >>>> >>>> So that tells you what''s wrong with your form, eh? :-) >>>> >>>> -- >>>> Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >>>> http://about.me/**hassanschroeder <http://about.me/hassanschroeder> >>>> twitter: @hassan >>>> >>> -- >>> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/rubyonrails-talk/-/DWnPNOCF_jEJ. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> -- >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.