# Redirect to\_back

**URL:** <https://www.ruby-forum.com/t/redirect-to-back/172920>\
**Category:** Rails\
**Created:** [July 29, 2009, 11:49pm UTC](https://www.ruby-forum.com/t/redirect-to-back/172920 "2009-07-29T23:49:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 29, 2009, 11:49pm UTC](https://www.ruby-forum.com/t/redirect-to-back/172920/1 "2009-07-29T23:49:39Z")

</div>

I am seeing some more differences between 1.2.x and 2.3.2 and they just  
baffle me.

def some\_method  
if params[:report][:salesmancode].to\_s == ‘’ || !  
params[:report][:periodno]  
flash[:message] = “You forgot to select an employee or pick a time  
period”  
redirect\_to :back  
else  
blah, blah  
end  
render :layout =\> false  
end

and I get a message about not being able to render/direct to more than 1  
time. Why doesn’t ‘redirect\_to :back’ simply end processing and redirect  
the user? Is there some better way of doing this now?

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 30, 2009, 12:01am UTC](https://www.ruby-forum.com/t/redirect-to-back/172920/2 "2009-07-30T00:01:57Z")

</div>

On Wed, 2009-07-29 at 16:49 -0500, Greg D. wrote:

> > redirect\_to :back
> 
> return false

* * *

that worked…doesn’t show my flash message so obviously something  
changed with flash. I thought it came from session but I can’t find it  
in the API.

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 29, 2009, 11:51pm UTC](https://www.ruby-forum.com/t/redirect-to-back/172920/3 "2009-07-29T23:51:25Z")

</div>

On Wed, Jul 29, 2009 at 4:48 PM, Craig W.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am seeing some more differences between 1.2.x and 2.3.2 and they just  
> baffle me.
> 
> def some\_method  
> if params[:report][:salesmancode].to\_s == ‘’ || !  
> params[:report][:periodno]  
> flash[:message] = “You forgot to select an employee or pick a time  
> period”  
> redirect\_to :back

return false

> else  
> blah, blah  
> end  
> render :layout =\> false  
> end
> 
> and I get a message about not being able to render/direct to more than 1  
> time. Why doesn’t ‘redirect\_to :back’ simply end processing and redirect  
> the user? Is there some better way of doing this now?

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [July 30, 2009, 1:09am UTC](https://www.ruby-forum.com/t/redirect-to-back/172920/4 "2009-07-30T01:09:16Z")

</div>

Hi Craig,

On Wed, 2009-07-29 at 14:48 -0700, Craig W. wrote:

> ```
> blah, blah
> 
> ```

render :layout =\> false

> end  
> end
> 
> and I get a message about not being able to render/direct to more than 1  
> time. Why doesn’t ‘redirect\_to :back’ simply end processing and redirect  
> the user? Is there some better way of doing this now?

It is a little confusing but the short answer is don’t count on render  
and redirect statements executing immediately. The best fix here is to  
put your render :layout =\> false inside your else clause. That way  
there’s no possibility of rendering twice.

HTH,  
Bill
