You're making it harder than it needs to be, and I don't think you're
understanding the relationships you are setting up.
Since a Note has many types, if you did this at the console:
>>> note = Note.find :first
you would have a note. To list its types:
>>> note.types
Since this is an array, you would have to find all the types this note
had if you wanted to, say, display them. Something like:
note.types.each do |type|
puts type.type_name
end
(in standard non-erb lingo)
If you were wanting to print all the types as you were trying to do in a view:
<% @notes.each do |note| %>
<% note.types.each do |type| %>
<%= h(type.type_name) %>
<% end %>
<% end %>
Or, more simply:
<% @notes.each do |note| %>
<%= h(note.types.join(", ") %>
<% end %>
I would consider getting rid of the name "type_name" and instead
calling it "name". Also, you might want "has_many :types" rather than
"has_many :type"
On Sun, Feb 22, 2009 at 7:25 AM, Matt Monsen
<[email protected]> wrote:
>
>
> class Note < ActiveRecord::Base
> has_many :type
> end
>
> class Type < ActiveRecord::Base
> belongs_to :note
> end
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---