Display inputs (columns of 2 tables) in form from 2 tables

I used nifty scaffolding for create controller ‘A’. For this controller
I have in DB table(again called ‘A’).

I have view, in which is a form for entering information. These data
will be stored in database. But was request have in this form input that
isn’t in table ‘A’ (column), but in table ‘B’.

<%= form_for @a do |u| %>
<%= u.error_messages %>

<%= u.label :name %>
<%= u.text_field :name %>

<%= u.label :age %>
<%= u.text_field :age %>

<%= u.label :email %>
<%= u.text_field :email %>

...

Input called ‘name’ will be stored in table ‘A’ (into column ‘name’),
input called ‘age’ will be stored in table ‘B’ (into column ‘age’).

I want display this form in browser, I am getting error:

undefined method `age’ for…

Can you help me, please, what is needed for this situation for right
displaying the form?

You should better think in (and talk about) models than tables. If you
want two models being represented in one form it depends on how these
models are related to another how to design the form.

Maybe you need something like <%= fields_for u.b do |v| … (in the case
that a has_one :b and b belongs_to :a)

T.

Thanks for your hint, but… how I should edit my view by your message?
I tried to apply to my view, but I am not sure, how to do

And the relationships: between ‘A’ and ‘B’: 1:N
and ‘B’ and ‘A’: N:1

I am newbie… but I don’t know, why I am getting still that error…

In controller a_controller I have:

@a = A.new

and this variable - @a - I am giving to form in my view… but this
variable not contains column ‘age’ that is in the table ‘B’

Can someone help me, please, or give some tip where to search or where
to get ideas for the solution of this problem?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs