I am using Rails 2.3.8. I have this table Shops with the following data:
Shops Database Table
ID | country_id | notes
1 | 10 | test
2 | 10 | testing
3 | 12 | tested
In shop.rb I put belongs_to :country.
In my Country’s view.html.erb, I want to be able to show the related notes from Shops table. Such in this case, in the page http://localhost:3000/countries/10, notes from ID1 and ID2 of Shops should appear in this page.
Can someone enlighten me how to achieve this? Thank you very much.
You also need to add in country.rb
has_many :shops. So now, from the html you can doby adding the
has_manyyou make the relationship bidirectional, and you can navigate to from shop -> country or from country -> shops.