同一模型的多个 has_manys
我有这些模型:
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
和此视图:
person#show
<% @person.messages_to_person.each do |message| %>
<%=h message.title %>
<% end %>
但我收到此错误:
People#show 中的类型错误
显示 app/views/people/show.html.erb 第 26 行引发的位置:
无法将符号转换为字符串
提取的源代码(在#26行附近):
23:<%=h @person.biography %> 24: 25: 26: <% @person.messages_to_person.each |message| %> 27: 28:<%结束%> 29:
我基本上想要它,以便人们可以互相发送消息。
谁能帮助我吗?谢谢。
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 basically want it so that people can send each other messages.
Can anyone help me? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
:class_name
应该是string
The problem is
:class_name
should be astring