记录 id 116 不存在,因此它应该将 nil 返回到 @conversation。
我试图让它在它为零时重定向,但是当我访问 example.com/messages/show?id=116 时它仍然显示错误。
错误是
未定义的方法“is_participant?” 对于零:NilClass
我肯定看到/usr/local/lib/ruby/gems/1.9.1/gems/mailboxer-0.7.0/app/models/conversation.rb中存在“is_participant”方法
消息控制器.rb
def show
@conversation = Conversation.find_by_id(params[:id])
unless @conversation.is_participant?(current_user)
flash[:alert] = "You do not have permission to view that conversation."
redirect_to :controller => 'messages', :action => 'received'
end
@messages = Message.find_by_id(params[:id])
current_user.read(@conversation)
end