Theo Graham-brown
2007-Nov-11 21:39 UTC
Forms containing checkboxes and collections/object lists
Hi, I''m really struggling to understand how to get checkboxes to work on a list of objects. Essentially I have this: - An Issue model which has_many articles - An Article model which belongs to issue So, I am pulling up a list of articles, all that are of type ''ready'' and either have an issue_id of 0 or article.issue_id == issue.id I want to have a check box after each in the table. It will be checked if you wish add the article to the current issue and unchecked if you wish to set the issue_id for the article to 0 and not include it. How in the blue blazes of hell do I do this with action view? The ''form_for'' helper only seems to refer to on object not a collection. On page 498 of ''Agile Web Development with Rails'' there''s a section about ''Forms Containing Collections'' which implies you can use a text field easily enough and this code works, adding an id into each text field''s ID. However, doing the same thing with ''check_box_tag'' fails brutally (maybe I don''t understand this tag). So I tried with ''check_box'' but all this does is give me an error like this: undefined method `delete'' for 1:Fixnum referencing the ''check_box'' tag. I don''t have ''delete'' anywhere in my code. I have tried to look over this: http://wiki.rubyonrails.org/rails/pages/CheckboxHABTM but there is querying of the database in the rhtml code, which seems wrong and not something I''m entirely sure I can easily achieve. Can someone give me a clear and easy way to do this sort of checkbox use? Surely this has got to be one of the most basic uses of a checkbox in code yet it seems hard to find something about? Any help will be appreciated, even if it''s just a ''DURR!'' and a link to a very clear code example. Thanks muchly, Theo -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
randomutterings...
2007-Nov-12 15:04 UTC
Re: Forms containing checkboxes and collections/object lists
Check out this railscast. http://railscasts.com/episodes/17 On Nov 11, 4:39 pm, Theo Graham-brown <rails-mailing-l...@andreas- s.net> wrote:> Hi, > > I''m really struggling to understand how to get checkboxes to work on a > list of objects. Essentially I have this: > > - An Issue model which has_many articles > - An Article model which belongs to issue > > So, I am pulling up a list of articles, all that are of type ''ready'' and > either have an issue_id of 0 or article.issue_id == issue.id > > I want to have a check box after each in the table. It will be checked > if you wish add the article to the current issue and unchecked if you > wish to set the issue_id for the article to 0 and not include it. > > How in the blue blazes of hell do I do this with action view? The > ''form_for'' helper only seems to refer to on object not a collection. > > On page 498 of ''Agile Web Development with Rails'' there''s a section > about ''Forms Containing Collections'' which implies you can use a text > field easily enough and this code works, adding an id into each text > field''s ID. However, doing the same thing with ''check_box_tag'' fails > brutally (maybe I don''t understand this tag). > > So I tried with ''check_box'' but all this does is give me an error like > this: > > undefined method `delete'' for 1:Fixnum > > referencing the ''check_box'' tag. I don''t have ''delete'' anywhere in my > code. > > I have tried to look over this:http://wiki.rubyonrails.org/rails/pages/CheckboxHABTMbut there is > querying of the database in the rhtml code, which seems wrong and not > something I''m entirely sure I can easily achieve. > > Can someone give me a clear and easy way to do this sort of checkbox > use? Surely this has got to be one of the most basic uses of a checkbox > in code yet it seems hard to find something about? > > Any help will be appreciated, even if it''s just a ''DURR!'' and a link to > a very clear code example. > > Thanks muchly, > Theo > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Theo Graham-brown
2007-Nov-12 18:46 UTC
Re: Forms containing checkboxes and collections/object lists
Chris Barnes wrote:> Check out this railscast. > > http://railscasts.com/episodes/17 > > On Nov 11, 4:39 pm, Theo Graham-brown <rails-mailing-l...@andreas-The problem is I''m not using HABTM. There will only ever be one article in any given Issue, though an issue will have many articles. THis doesn''t seem to work for my requirements. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Theo Graham-brown
2007-Nov-12 18:58 UTC
Re: Forms containing checkboxes and collections/object lists
Chris Barnes wrote:> Check out this railscast. > > http://railscasts.com/episodes/17 > > On Nov 11, 4:39 pm, Theo Graham-brown <rails-mailing-l...@andreas-Apologies. I think it will work! Thanks a lot. The webcast is much easier to follow than the Wiki entry on a similar subject. I maybe be back, though. :-( Thanks for your patience. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---