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 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 -~----------~----~----~----~------~----~------~--~---
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
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
-~----------~----~----~----~------~----~------~--~---
class Country
....
def people_tribes
peoples.map{|p|p.tribe}.join('','')
end
end
On Dec 1, 8:51 pm, wfisk
<william.f...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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 viahttp://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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
William, thanks for your help in resolving this issue. It works great now. Thanks a lot. Please, if you know any good book or online material on Ruby/InstantRails 2.0.2, please post it in the Forum. Thanks Cypray wfisk wrote:> class Country > .... > > def people_tribes > peoples.map{|p|p.tribe}.join('','') > end > end-- 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 -~----------~----~----~----~------~----~------~--~---
Agile Web Development with Rails is the standard for getting up and running... also I like Practical Rest with Rails On Dec 2, 12:44 am, Jay Mark <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> William, thanks for your help in resolving this issue. > It works great now. Thanks a lot. > > Please, if you know any good book or online material > on Ruby/InstantRails 2.0.2, please post it in the Forum. > Thanks > Cypray > > wfisk wrote: > > class Country > > .... > > > def people_tribes > > peoples.map{|p|p.tribe}.join('','') > > end > > end > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jay, You''re confusing Rails with InstantRails. Rails is the web framework, Instant Rails is a package containing Rails + web server + DB, etc. Google for Rails books, there are also plenty of suggestions in other topics in this group. Finally, if you have the time, I would start by 1st learning Ruby and then moving to Rails with AWDR, The Rails Way, etc. Cheers, Sazima On Dec 1, 10:44 pm, Jay Mark <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> William, thanks for your help in resolving this issue. > It works great now. Thanks a lot. > > Please, if you know any good book or online material > on Ruby/InstantRails 2.0.2, please post it in the Forum. > Thanks > Cypray > > wfisk wrote: > > class Country > > .... > > > def people_tribes > > peoples.map{|p|p.tribe}.join('','') > > end > > end > > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sazima, You are so right Sazima. I am confused like a beginner. Thanks for clearing that up for me. I have started learning Ruby. Thanks for all the suggestions guys. Jay. Sazima wrote:> Jay, > > You''re confusing Rails with InstantRails. Rails is the web framework, > Instant Rails is a package containing Rails + web server + DB, etc. > > Google for Rails books, there are also plenty of suggestions in other > topics in this group. Finally, if you have the time, I would start by > 1st learning Ruby and then moving to Rails with AWDR, The Rails Way, > etc. > > Cheers, Sazima-- 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 -~----------~----~----~----~------~----~------~--~---