User モデル、Post モデル、Interest モデルがあります。
User has_many posts through interests
User has_many interests
Post has_many users through interests
Post has_many interests
Interest belongs to Post
Interest belongs to User
Application_Controller は次のとおりです。
class ApplicationController < ActionController::Base
before_filter :login_from_cookie
before_filter :find_user_interests
helper :all # include all helpers, all the time
session :session_key => '_blah_session'
include AuthenticatedSystem
def find_user_interests
@user_interests = current_user ? current_user.interests : []
true
end
end
Application.html.erb には次のようなものがあります。
<%= render :partial => "users/interests", :object => @user_interests %>
_interests.html.erb パーシャルは次のとおりです。
ul
<% unless current_user.nil? then -%>
<% @user_interests.each do |interest| -%>
li<%= interest.post.title %>/li
<% end %>
<% end -%>
/ul
localhost:3000/posts/1 ではパーシャルが正常に表示されますが、localhost:3000/posts ではエラーが発生するため、上記の _interests.html.erb パーシャルundefined method 'title' for nil:NilClass
の行にエラーが発生します 。li<%= interest.post.title %>/li
一体何が問題になるのでしょうか?
ティア