Multiple nested attributes of the same type

Hi all,

0 down vote favorite

I have two models - “symbols” and “users”. Among other attributes,
symbols has “created_by_id” and “updated_by_id” attributes which are
id’s of users that created/updated a certain symbol entry.

Let’s say I want to display the symbols table with their “symbol”
attribute and the nested “created by” and “updated by” (user.username)
attributes for each symbol entry. Resulting table should look something
like this:

symbol created_by updated_by

symbol1 username1 username2
symbol2 username1 username2

How can I achieve this? I guess I need accepts_nested_attributes_for
:user and probably has_one :user (?) in my Symbol model. Do I also need
belongs_to :user in my User model?

After the models are set up properly, how can I access the username of
users associated with “created_by_id” and “updated_by_id” in my view?

I have an edit form where I used nested form like this (which works
fine):

<%= form_for @symbol do |f| %>
Symbol:
<%= f.text_field :symbol %>
<%= f.fields_for :kanji do |kf| %>
Meaning:
<%= kf.text_field :meaning %>

Onyomi:
<%= kf.text_field :onyomi %>

Kunyomi:
<%= kf.text_field :kunyomi %>

<% end %>
<%= f.submit “Save” %>
<% end %>

but I couldn’t figure out how to do something similar in this case where
I have two nested attributes associated with the same symbol.

I’m new to rails so perhaps I got the whole idea of how to do this
wrong. If there is a better than what I just explained how I want to do
it, please correct me.

Thank you

the answer is to be found here:

On 1 July 2013 19:15, Rick [email protected] wrote:

the answer is to be found here:
Active Record Associations — Ruby on Rails Guides

Also work right through a good tutorial such as railstutorial.org
(which is free to use online). This will show you the basics of
Rails.

Colin