Hi, I'm also new to rails and I'm trying the same thing. I'm extending the Getting Started example to learn.
I've made an extra table called `clients`: (id | name) and I already had the table `posts`: (id | title | content | created_at | updated_at | client_id). The index view for posts loops through all the posts I want to show the client name. I believe the way to do this is like this: <% @posts.each do |post| %> <tr> <td><%=h post.client.name %></td> <td><%=h post.title %></td> [...] I have set up all the assocations (posts belongs_to client, client has_many posts) but it doesn't work. I'm probably making a simple mistake but hey, I'm new :) Thanks in advance. On May 24, 10:08 pm, Colin Law <clan...@googlemail.com> wrote: > Also you will make life much easier for yourself if you stick to the rails > naming conventions, so the column names will be id, name, price, country_id > and id, country_name. > > You might find this helpfulhttp://guides.rubyonrails.org/getting_started.html > > Colin > > 2009/5/24 Hemali Chauhan <hemali.chauh...@gmail.com> > > > > > Hi, > > > You must have defined has_many and belongs_to association for Country > > and Product. > > > So now you can directly write: > > @product.country.name > > > -Hemali Chauhan > > > On May 24, 3:14 pm, Mike75 <youp....@gmail.com> wrote: > > > hi > > > i'm trying things out with rails, and I'm having trouble with showing > > > a list of products. > > > i hope someone can help me out with this.. > > > > my tables are simple and it contains the following fields > > > > product table : id | Name | Price | Country_id > > > country table : id | CountryName > > > > and I input products info with selected id numbers from the "country" > > > table and insert the country.id into products.Country_id. > > > > I am trying to show countryName from the country table on the products > > > list. > > > > it would be wonderful if anyone can help me out with this.. > > > > thank you --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---