Why does this code return an error?
Is it because my association from Community or CommunityTopics are not set up correctly?
undefined method `user_profile' for nil:NilClass
<% @community.community_topics.each do |topic| %>
<li>
<%= link_to topic.user.user_profile.nickname, community_topic_path(@community, topic) %>
</li>
<% end %>
I have 4 models such as
- User
- UserProfile (This is always set with User one to one)
- Community
CommunityTopic
- Users can create Community as much as they want.
- Users can post Topics to any Community as much as they want.
In this case how the association should be like?
Is my statement fine??
User
has_one :user_profile
has_many :communities
has_many :community_topics
UserProfile
belongs_to :user
Community
belongs_to :user
has_many :community_topics
CommunityTopics
belongs_to :user
belongs_to :community