I am sure there's a few ways of doing this. Here's an easy one:
declare a method in the Country class and use that.
class Country
....
def people_tribes
peoples.map{|p|p.tribes}.join(',')
end
end
now in your view use country.people_tribes
William
Jay Mark wrote:
> I am new to Ruby/InstantRails. I am using InstantRails 2.0.2 with mysql
> database
>
> My application is named Area, it has two tables: people and country
> Table people has two columns: name and tribe
> Table country has two columns: location and population
>
> In the models I have:
> class People < ActiveRecord::Base
> belongs_to :country
> end
> class Country < ActiveRecord::Base
> has_many :peoples
> end
>
> I have country_id in the people's table.
>
> I know I can do this:
> <% @peoples.each do |people| %>
> <td><%= people.name %></td>
> <td><%= people.country.location %></td> // This works
>
> What I want to do is to display location on country\index.html.erb
>
> <% @countries.each do |country| %>
> <td><%= link_to country.location, :action => "show", :id => country.id
> %></td>
>
>
> Then when I click on 'location' as a link, I want to display the 'tribe'
> along side with 'population' for that 'location' on
> view\country\show.html
>
> <td><%=h @country.population %></td> // this works
>
> <td><%=h @country.tribe %></td> // this does not works
>
> My question is, how can I reference a column from the people's table
> with a country's object? I know it works the other round.
>
> Please help!
> Cypray
> --
> 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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---