记录ID 116不存在,所以它应该返回nil给@conversation。
我试图让它在得到零时重定向,但是当我访问example.com/messages/show?id=116时它仍然显示错误。如何避免无对象上的错误
该错误是
未定义的方法`is_participant?对于零:NilClass
我确实看到“is_participant的方法在
/usr/local/lib/ruby/gems/1.9.1/gems/mailboxer-0.7.0/app/models/conversation存在。 RB
messages_controller.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
它工作完美,因为我想。谢谢! – MKK 2012-07-06 06:43:18