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 -- Posted via http://www.ruby-forum.com/. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Feb 15, 2012 at 5:36 AM, Ajit Teli <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Javier, I think that this approach is correct but I guess that if you use transaction it will be better for your system performance. :D -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Feb 15, 2012 at 8:37 AM, Bruno Meira <goesmeira-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Javier, > I think that this approach is correct but I guess that if you use > transaction it will be better for your system performance. > :D > >For example when I want to add several items using checkboxes I add it by doing this Model.another_model_ids = params[:ids] (Product.category_ids = params[:ids]) for example or just by doing Model.another_models << AnotherModel.find(params[:id]) I saw the first one on a railscast and it seems to work when adding, but I''ve never done something like deleting several items Maybe my approach is incorrect :) I''m kind of new on rails and... I''ve never used transactions, you mean this? http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html 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 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Exactly, Using Transactions will be save you some DB connections. It''s simple to use it, take a look better in that url... it explains well how to use it. :D -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Javier, Following is the controller-action which I am using to delete the tags. But the issue is with the ''tag_ids[]'' array. The array will be always nil. So i am unable to delete any of the tags. def delete_tag @delete_tags = params[:tag_ids] if request.delete? @delete_tags.each do |del| Tag.destroy(del) end end redirect_to :action => :index, :tab => ''tags'' end When I click on the link, I am getting following error message: NoMethodError in AdminController#delete_tag You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each Thank you all -- Posted via http://www.ruby-forum.com/. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wed, Feb 15, 2012 at 11:00 PM, Ajit Teli <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Javier, > > Following is the controller-action which I am using to delete the tags. > But the issue is with the ''tag_ids[]'' array. The array will be always > nil. So i am unable to delete any of the tags. > > > def delete_tag > @delete_tags = params[:tag_ids] > if request.delete? > @delete_tags.each do |del| > Tag.destroy(del) > end > end > redirect_to :action => :index, :tab => ''tags'' > end > > > When I click on the link, I am getting following error message: > > NoMethodError in AdminController#delete_tag > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > >What is the code for the link? -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 15, 2012, at 11:02 PM, Javier Quarite wrote:> > > On Wed, Feb 15, 2012 at 11:00 PM, Ajit Teli <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > Hi Javier, > > Following is the controller-action which I am using to delete the tags. > But the issue is with the ''tag_ids[]'' array. The array will be always > nil. So i am unable to delete any of the tags. > > > def delete_tag > @delete_tags = params[:tag_ids] > if request.delete? > @delete_tags.each do |del| > Tag.destroy(del) > end > end > redirect_to :action => :index, :tab => ''tags'' > end > > > When I click on the link, I am getting following error message: > > NoMethodError in AdminController#delete_tag > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > > > What is the code for the link?And what do your checkboxes look like in your view? The name you give them will determine how they show up in your params hash. And the form tag you enclose them in will determine whether they even make it to the controller at all. Walter> > > -- > 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Javier, Following is the controller-action which I am using to delete the tags. But the issue is with the ''tag_ids[]'' array. The array will be always nil. So i am unable to delete any of the tags. def delete_tag @delete_tags = params[:tag_ids] if request.delete? @delete_tags.each do |del| Tag.destroy(del) end end redirect_to :action => :index, :tab => ''tags'' end When I click on the link, I am getting following error message: NoMethodError in AdminController#delete_tag You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each Thank you all -- Posted via http://www.ruby-forum.com/. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.