Hello everybody, new to Ruby on Rails... i''m following the tutorial at http://www.onlamp.com/pub/a/onlamp/2007/01/05/revisiting-ruby-on-rails-revisited-2.html?page=1 but i''m having some issues... now what i want to know is how-to display in a list, the value of a field that is pointed by the fk.. example: table categories: id, name table recipes: id, category_id, title, description, .. where recipes.category_id is a fk for categories.id i''ve the list view for the recipes where i want to display something like: Recipe Title Category Smoked salmon on rocket leaves Starters now how can do that? in my views list.rhtml i''ve something like this: <% for recipe in @recipes %> <tr> <td> <%= link_to %Q{#{recipe.title}}, :action => ''show'', :id => recipe %> <%= link_to ''(del)'', { :action => ''destroy'', :id => recipe }, :confirm => ''Are you sure?'', :post => true %> </td> <td> <%= link_to %Q{#{XXXXXXXXXX}}, {:action => ''list'', :category_id => recipe.category_id} %> </td> </tr> <% end %> what am i supposed to put in XXXXXXXXXX ? to see the category name instead of the category_id? (infact i have recipe.category_id thanks for your help. -- 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 -~----------~----~----~----~------~----~------~--~---
Dave Goodchild
2007-Apr-16 14:50 UTC
Re: get the value of a field pointed by a foreign key
I think you need to look into Associations, which manage the table relationships in your models. On 4/16/07, Pingala Pingala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello everybody, > > new to Ruby on Rails... > i''m following the tutorial at > > http://www.onlamp.com/pub/a/onlamp/2007/01/05/revisiting-ruby-on-rails-revisited-2.html?page=1 > > but i''m having some issues... > > now what i want to know is how-to display in a list, the value of a > field that is pointed by the fk.. > > example: > > table categories: > id, name > > table recipes: > id, category_id, title, description, .. > > where recipes.category_id is a fk for categories.id > > i''ve the list view for the recipes where i want to display something > like: > > Recipe Title Category > Smoked salmon on rocket leaves Starters > > now how can do that? > > in my views list.rhtml i''ve something like this: > <% for recipe in @recipes %> > <tr> > <td> > <%= link_to %Q{#{recipe.title}}, :action => ''show'', :id => recipe > %> > <%= link_to ''(del)'', { :action => ''destroy'', :id => recipe }, > :confirm => ''Are you sure?'', :post => true %> > </td> > <td> > <%= link_to %Q{#{XXXXXXXXXX}}, {:action => ''list'', :category_id => > recipe.category_id} %> > </td> > </tr> > <% end %> > > what am i supposed to put in XXXXXXXXXX ? to see the category name > instead > of the category_id? (infact i have recipe.category_id > > thanks for your help. > > -- > Posted via http://www.ruby-forum.com/. > > > >-- http://www.web-buddha.co.uk --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---