Re: About a simple insert

Matthew Lagace
Tue, 15 May 2007 15:20:05 -0000

Matthew Lagace wrote:
> Bob Showalter wrote:
> On 5/15/07, Matthew Lagace
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:
>
> Ok, my problem is that I have a form with a client''s information.
Now in
> the form, I ask the client for his info, which inserts into the table
> "clients", and then I have another text input where he has to
provide a
> specific detail that i want to be inserted into the table
"details". How
> can I insert this data into 2 different tables?

 It sounds like you should establish an association between the
two
> models:
>
>   class Client < ActiveRecord::Base
>     has_many :details
>   end
>
>  class Detail < ActiveRecord::Base
>    belongs_to :client
>  end
>
> This would require a client_id column in the details table.
>
> Then, when the form is submitted, you would do something like:
>
>   client = Client.new(params[:client])
>   client.details.build(params[:detail])
>   client.save
>
> The one save inserts both the clients and details rows.
>
> HTH
>
>
> Ok i got that, but in my new.rhtml, what do I put in the value field of
> my text input? I tried <%= @client.details.name %> but it
doesn''t work.
>
> Thanks alot for the help

Oh and what do i put as my id and name for my text input also?

Thanks