【发布时间】:2012-12-24 16:52:50
【问题描述】:
为什么这段代码会返回错误?
是不是因为我来自Community 或CommunityTopics 的关联设置不正确?
nil:NilClass 的未定义方法 `user_profile'
<% @community.community_topics.each do |topic| %>
<li>
<%= link_to topic.user.user_profile.nickname, community_topic_path(@community, topic) %>
</li>
<% end %>
我有 4 个模型,例如
- 用户
- UserProfile(始终与用户一对一设置)
- 社区
-
社区主题
- 用户可以根据需要创建社区。li>
- 用户可以根据需要向任何社区发布主题。
这种情况下的关联应该是怎样的?
我的陈述好吗??
用户
has_one :user_profile
has_many :communities
has_many :community_topics
用户资料
belongs_to :user
社区
belongs_to :user
has_many :community_topics
社区主题
belongs_to :user
belongs_to :community
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 associations