From: Israel Guerra Date: 2008-06-11T20:17:07+09:00 Subject: Re: Rails - relations ------=_Part_26504_1733727.1213183034782 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Oh, it's true, i always end up mixing up rails list with ruby list! Thanks for the tips though :) On Wed, Jun 11, 2008 at 3:46 AM, Damjan Rems wrote: > Israel Guerra 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 > > -- > Posted via http://www.ruby-forum.com/. > > -- Guerra ------=_Part_26504_1733727.1213183034782--