# Rails - relations

**URL:** <https://www.ruby-forum.com/t/rails-relations/140121>\
**Category:** Ruby\
**Created:** [June 11, 2008, 2:03am UTC](https://www.ruby-forum.com/t/rails-relations/140121 "2008-06-11T02:03:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 11, 2008, 2:03am UTC](https://www.ruby-forum.com/t/rails-relations/140121/1 "2008-06-11T02:03:54Z")

</div>

Hi ppl.

I am noob in rails and started an app to learn. I have the following  
scenario:

table client with fileds: name, second\_name  
table phone with fields: number, client\_id  
table address with fields: street, number, client\_id

The migrations worked ok and the fields are created.

Now i defined in the model that

for client:  
has\_many :phones  
has\_many :adresses

for phones and adresses:  
belongs\_to :client

I made a form to get some of these fields and add to the database:

\<% form\_for(:clients) do |f| %\>

**Name** \<%= f.text\_field :name %\>

**Second Name** \<%= f.text\_field :second\_name%\>

**Number** \<%= f.text\_field :number%\>

\<%= f.submit "Add" %\>

\<% end %\>

And in the controller i try to save it to the DB:

@clients = Clients.new(params[:clients])  
@clients.save

When i submit i get an error saying that number is not a method, it  
means it  
didnt associate number with a cliente. It’s not “joining” the tables.

Where did i made a mistake here?

Thanks guys.

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 11, 2008, 8:47am UTC](https://www.ruby-forum.com/t/rails-relations/140121/2 "2008-06-11T08:47:04Z")

</div>

Israel G. wrote:

> Hi ppl.
> 
> I am noob in rails and started an app to learn. I have the following  
> scenario:
> 
> table client with fileds: name, second\_name  
> table phone with fields: number, client\_id  
> table address with fields: street, number, client\_id
> 
> The migrations worked ok and the fields are created.
> 
> Now i defined in the model that
> 
> for client:  
> has\_many :phones  
> has\_many :adresses
> 
> for phones and adresses:  
> belongs\_to :client
> 
> I made a form to get some of these fields and add to the database:
> 
> \<% form\_for(:clients) do |f| %\>
> 
> **Name** \<%= f.text\_field :name %\>
> 
> **Second Name** \<%= f.text\_field :second\_name%\>
> 
> **Number** \<%= f.text\_field :number%\>
> 
> \<%= f.submit "Add" %\>
> 
> \<% end %\>
> 
> And in the controller i try to save it to the DB:
> 
> @clients = Clients.new(params[:clients])  
> @clients.save
> 
> When i submit i get an error saying that number is not a method, it  
> means it  
> didnt associate number with a cliente. It’s not “joining” the tables.
> 
> Where did i made a mistake here?
> 
> Thanks guys.

1. Try asking this questions in rail snewsgroup
2. You are trying to access field from other table. The right way to  
access the filed would be:  
client.phones[n].number

and I don’t know if this can be done with simple form.

by  
TheR

---

<div class="post-metadata">

**Author:** ![Israel\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@Israel\_G](https://www.ruby-forum.com/u/Israel_G)\
**Post date:** [June 11, 2008, 1:54pm UTC](https://www.ruby-forum.com/t/rails-relations/140121/3 "2008-06-11T13:54:35Z")

</div>

Oh, it’s true, i always end up mixing up rails list with ruby list!

Thanks for the tips though 🙂
