Associations Confusion

Doing @emresa.usiario doesn't work for new records, I think.

Try doing @usiario =, and <% fields_for :usuario,
@usuario do |usr|%>.

Not sure, though, but try it.

Forgot it was a has_many, go @usiario = (plural
of usiario)

Hi Marcelo.

You should be using the build method provided by has_many instead of
new. That way the usuario-empresa relationship is created (the
empresa_id is assigned). Using new just creates a new usuario. The line
should look like this

@usuario =

If you want to fill the usuario with the form data you could do

@usuario =[:usuario])

In any case, using the build method will make AR save the usuario when
you save the empresa, so there will be no need to do


Marcelo Junior escribió: