Double reversible rails

Not sure how to get this error:

AbstractController::DoubleRenderError users#create 

When in my controller I received this code:

 render 'new' and return 

I got a log from bugsnag that says I got an error on this line.

This is the code of the create method:

 def create back_button and return if params[:back_button] @profile = current_user.build_profile(params[:user]) 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 end 

I have a filter in this controller:

 before_filter :signed_in_user def signed_in_user unless signed_in? store_location redirect_to signin_url, notice: "Please sign in." end end 
+8
ruby ruby-on-rails
source share
4 answers

Try:

 class UsersController < ApplicationController before_filter :signed_in_user def create return back_button if params[:back_button] @profile = current_user.build_profile(params[:user]) if @profile.nil? || current_user.nil? || @profile.user.nil? sign_out return redirect_to signup_path end if @profile.new_record? render 'new' else redirect_to more_questions_path end end private def signed_in_user unless signed_in? store_location return redirect_to signin_url, notice: "Please sign in." end end end 

Rationale: x and return means x and return nil , so it returns nil . In fact, you are trying to shorten the action of the controller and return redirect_to ...

+10
source share

And does nothing for you.

In every place where you have

 xxx and return 

replace it with

 xxx return 

For exameple:

 redirect_to signup_path return 

This should work more as you would expect from it.

+5
source share

You have a render and a redirect. You must choose one.

+2
source share

I assume that redirect_to signup_path returns either nil or false , so your and return not executed.

You can fix this in many ways, the easiest way to replace

 redirect_to signup_path and return 

by

 redirect_to signup_path return 

However, I suggest you make big changes. Try to change it.

 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 

Thus, it is clear that only one path is possible without relying on a refund.

0
source share

All Articles