Multiple has_many's of the same model
- by Koning Baard
I have these models:
Person
has_many :messages_form_person, :foreign_key => :from_user_id, :class_name => :messages
has_many :messages_to_person, :foreign_key => :to_user_id, :class_name => :messages
Message
belongs_to :to_person, :foreign_key => :to_user_id, :class_name => :person
belongs_to :from_person, :foreign_key => :to_user_id, :class_name => :person
And this view:
person#show
<% @person.messages_to_person.each do |message| %>
<%=h message.title %>
<% end %>
But I get this error:
TypeError in People#show
Showing app/views/people/show.html.erb where line #26 raised:
can't convert Symbol into String
Extracted source (around line #26):
23: <%=h @person.biography %>
24: </p>
25:
26: <% @person.messages_to_person.each do |message| %>
27:
28: <% end %>
29:
I basicly want that people can send eachother messages.
Can anyone help me? Thanks.