# New to Rails... Help!

**URL:** <https://www.ruby-forum.com/t/new-to-rails-help/154576>\
**Category:** Rails\
**Created:** [December 1, 2008, 8:05pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576 "2008-12-01T20:05:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 1, 2008, 8:05pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/1 "2008-12-01T20:05:02Z")

</div>

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| %\>

\<%= people.name %\> \<%= people.country.location %\> // This works

What I want to do is to display location on country\index.html.erb

\<% @countries.each do |country| %\>

\<%= link\_to country.location, :action =\> "show", :id =\> country.id %\>

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

\<%=h @country.population %\> // this works \<%=h @country.tribe %\> // 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

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 1, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/2 "2008-12-01T20:52:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 1, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/3 "2008-12-01T20:54:01Z")

</div>

class Country  
…

def people\_tribes  
peoples.map{|p|p.tribe}.join(’,’)  
end  
end

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 2, 2008, 12:29pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/4 "2008-12-02T12:29:59Z")

</div>

Agile Web D. with Rails is the standard for getting up and  
running… also I like Practical Rest with Rails

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 2, 2008, 1:44am UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/5 "2008-12-02T01:44:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 2, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/6 "2008-12-02T19:01:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![den1jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@den1jay](https://www.ruby-forum.com/u/den1jay)\
**Post date:** [December 2, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/new-to-rails-help/154576/7 "2008-12-02T15:56:04Z")

</div>

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
