如果用户控制器的语句显示操作

时间:2014-07-30 21:46:40

标签: ruby-on-rails

如果尝试将我的应用视为未注册用户,我会收到用户控制器展示操作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

0 个答案:

没有答案