如果尝试将我的应用视为未注册用户,我会收到用户控制器展示操作undefined method `letsgos' for nil:NilClass
的错误@letsgo = current_user.letsgos.build
。
如何添加if语句,以便未注册的用户可以查看显示页面?
def show
@user = User.find(params[:id])
@question = Question.where('recipient_id = ? and answer is not null', params[:id]).page(params[:page]).per_page(3)
@letsgo = current_user.letsgos.build
respond_to do |format|
format.html { render layout: 'new_application' }
format.js { render partial: 'questions/questions', locals: {questions: @question} }
end
end