Double render error rails

前端 未结 4 1610
借酒劲吻你
借酒劲吻你 2021-01-04 12:47

Not sure how its possible to get this error :

AbstractController::DoubleRenderError users#create

When in my controller I got this code :

4条回答
  •  灰色年华
    2021-01-04 13:30

    I suppose redirect_to signup_path is returning either nil or false, thus your and return is not being executed.

    You can fix this many ways, the simplest is replace

    redirect_to signup_path and return
    

    by

    redirect_to signup_path
    return
    

    Yet, I suggest you to do a bigger change. Try changing this

    if @profile.nil? || current_user.nil? || @profile.user.nil?
      sign_out
      redirect_to signup_path and return
    end
    
    if @profile.new_record?
      render 'new' and return
    else
      redirect_to more_questions_path and return
    end
    

    By

    if @profile.nil? || current_user.nil? || @profile.user.nil?
      sign_out
      redirect_to signup_path
    elsif @profile.new_record?
      render 'new'
    else
      redirect_to more_questions_path
    end
    

    This way it is clear that only one path can be taken, without relying on return.

提交回复
热议问题