i thought this was possible but it is not working for me. @items = Items.find(:all) in the view via a loop the goes thru all the rows. item.relationship.related_table_col this The error occurred while evaluating nil.name if i pass @one_item = Items.find(402) then it works. how do i set up this loop so that this would work? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You''ll need to paste your view code and get a little more detail on what you''re doing. I''ll point out a couple things though ... On Mon, Apr 7, 2008 at 9:18 AM, rashantha <rashantha-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > i thought this was possible but it is not working for me. > > @items = Items.find(:all)Model name''s are typically in the singular form ... this would look like: @items = Item.find :all> > > in the view via a loop the goes thru all the rows. > > item.relationship.related_table_col > > this The error occurred while evaluating nil.nameIt sounds as if you''re getting :all of the items, but one of them has a missing foreign key association in the database.> <http://nil.name> > > > if i pass @one_item = Items.find(402) > > then it works. > > how do i set up this loop so that this would work? > > >-- Bryan Ray http://www.bryanray.net "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Model name''s are typically in the singular form ... this would look like: > > @items = Item.find :allyes, i made a mistake on the post but that is accurate in the controller.> It sounds as if you''re getting :all of the items, but one of them has a > missing foreign key association in the database.can you please explain this. i am not following what you are saying. On Apr 7, 8:01 am, "Bryan Ray" <bryans...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You''ll need to paste your view code and get a little more detail on what > you''re doing. > > I''ll point out a couple things though ... > > On Mon, Apr 7, 2008 at 9:18 AM, rashantha <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > i thought this was possible but it is not working for me. > > > @items = Items.find(:all) > > Model name''s are typically in the singular form ... this would look like: > > @items = Item.find :all > > > > > in the view via a loop the goes thru all the rows. > > > item.relationship.related_table_col > > > this The error occurred while evaluating nil.name > > It sounds as if you''re getting :all of the items, but one of them has a > missing foreign key association in the database. > > > <http://nil.name> > > > if i pass @one_item = Items.find(402) > > > then it works. > > > how do i set up this loop so that this would work? > > -- > Bryan Rayhttp://www.bryanray.net > > "Programming today is a race between software engineers striving to build > bigger and better idiot-proof programs, and the Universe trying to produce > bigger and better idiots. So far, the Universe is winning."--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
SOLVED. thanks for the clue. bryan yes, some of the associations were nil and i had to check for this before outputting. so i did a an if statement and all works well thru the loop. yuk 2 days. if item.some_id == 0 no relationship else item.relationship.variable end. thanks. On Apr 7, 8:01 am, "Bryan Ray" <bryans...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You''ll need to paste your view code and get a little more detail on what > you''re doing. > > I''ll point out a couple things though ... > > On Mon, Apr 7, 2008 at 9:18 AM, rashantha <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > i thought this was possible but it is not working for me. > > > @items = Items.find(:all) > > Model name''s are typically in the singular form ... this would look like: > > @items = Item.find :all > > > > > in the view via a loop the goes thru all the rows. > > > item.relationship.related_table_col > > > this The error occurred while evaluating nil.name > > It sounds as if you''re getting :all of the items, but one of them has a > missing foreign key association in the database. > > > <http://nil.name> > > > if i pass @one_item = Items.find(402) > > > then it works. > > > how do i set up this loop so that this would work? > > -- > Bryan Rayhttp://www.bryanray.net > > "Programming today is a race between software engineers striving to build > bigger and better idiot-proof programs, and the Universe trying to produce > bigger and better idiots. So far, the Universe is winning."--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rashantha wrote:> SOLVED. > > thanks for the clue. bryan > > yes, some of the associations were nil and i had to check for this > before outputting. > so i did a an if statement and all works well thru the loop. yuk 2 > days. > > if item.some_id == 0 > no relationship > else > item.relationship.variable > end. > > thanks.It''s probably a bit cleaner to just check whether the association is nil if item.foo item.foo.variable end or even a simple 1 liner item.foo.variable if item.foo Or this would even work item.foo && item.foo.variable -- 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 -~----------~----~----~----~------~----~------~--~---