我想将@question.id
与数据库表Work
中的值进行比较。我怎么能在问题控制器的show动作中做到这一点?
我想将@question.id
与@community.community_activity
进行比较,但当我在问题控制器中执行此操作时,@community
为nil
:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.community_activity
如何解决这个问题?
if @question.id != @community.community_activity.for_communities(60).object_id and current_user.role.title.strip == "Test"
redirect_to 'public/access_denied.html'
return
答案 0 :(得分:1)
根据您向我们展示的内容,我所能提出的建议如下:
if @community.nil? || (@question.id != @community.community_activity.for_communities(60).id && current_user.role.title.strip == "Test")
redirect_to '/access_denied.html'
return
end
或许这更合适:
if (@community.nil? || @question.id != @community.community_activity.for_communities(60).id) && current_user.role.title.strip == "Test"
redirect_to '/access_denied.html'
return
end