Multiple has_many's of the same model

Posted by Koning Baard on Stack Overflow See other posts from Stack Overflow or by Koning Baard
Published on 2010-06-18T16:05:35Z Indexed on 2010/06/18 16:13 UTC
Read the original article Hit count: 214

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby