# Rescue rails errors

**URL:** <https://www.ruby-forum.com/t/rescue-rails-errors/147491>\
**Category:** Rails\
**Created:** [September 2, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/rescue-rails-errors/147491 "2008-09-02T14:15:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [September 2, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/rescue-rails-errors/147491/1 "2008-09-02T14:15:15Z")

</div>

Hi all,

Sometime, I get the following error in my application:

ActionController::InvalidAuthenticityToken in  
ManageController#site\_servers  
ActionController::InvalidAuthenticityToken

I tried to put the code in manage controller between begin … rescue  
… end but it didn’t catch the error.  
So I tried in the application.rb controller, I put the forgery code  
between begin … rescue … end, but it didn’t work neither.

How could I trap this error ?

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [September 2, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/rescue-rails-errors/147491/2 "2008-09-02T15:27:53Z")

</div>

On 2 Sep 2008, at 13:15, MR Damien wrote:

> … end but it didn’t catch the error.  
> The exception is raised before your action runs, so an rescue block  
> inside your action would do nothing. if you meant

class …  
begin  
def some\_action  
end  
end  
end

then that would only catch exceptions raised while ruby was loading  
the controller file (not when it was processing the request

> So I tried in the application.rb controller, I put the forgery code  
> between begin … rescue … end, but it didn’t work neither.

ditto

> How could I trap this error ?

see rescue\_action\_in\_public; rescue\_from

Fred

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [September 4, 2008, 2:55pm UTC](https://www.ruby-forum.com/t/rescue-rails-errors/147491/3 "2008-09-04T14:55:12Z")

</div>

Frederick C. wrote:

> On 2 Sep 2008, at 13:15, MR Damien wrote:
> 
> > … end but it didn’t catch the error.  
> > The exception is raised before your action runs, so an rescue block  
> > inside your action would do nothing. if you meant
> 
> class …  
> begin  
> def some\_action  
> end  
> end  
> end
> 
> then that would only catch exceptions raised while ruby was loading  
> the controller file (not when it was processing the request
> 
> > So I tried in the application.rb controller, I put the forgery code  
> > between begin … rescue … end, but it didn’t work neither.
> 
> ditto
> 
> > How could I trap this error ?
> 
> see rescue\_action\_in\_public; rescue\_from
> 
> Fred

I got it to work with rescue\_from but the redirection  
(redirect\_to(:controller =\> “login” )) I am doing is only done inside a  
little box using Ajax.

How could I tell the navigator to reload the whole page ?

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [September 4, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/rescue-rails-errors/147491/4 "2008-09-04T17:14:02Z")

</div>

On 4 Sep 2008, at 14:55, MR Damien [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ```
> > def some_action
> > 
> > ```
> > 
> > >
> 
> little box using Ajax.
> 
> How could I tell the navigator to reload the whole page ?

Render some rjs that does page.redirect\_to (which just generates  
window.location=…)

---

<div class="post-metadata">

**Author:** ![mrdamien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mrdamien](https://www.ruby-forum.com/u/mrdamien)\
**Post date:** [September 5, 2008, 8:49am UTC](https://www.ruby-forum.com/t/rescue-rails-errors/147491/5 "2008-09-05T08:49:00Z")

</div>

Frederick C. wrote:

> On 4 Sep 2008, at 14:55, MR Damien [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > ```
> > > def some_action
> > > 
> > > ```
> > > 
> > > >
> > 
> > little box using Ajax.
> > 
> > How could I tell the navigator to reload the whole page ?
> 
> Render some rjs that does page.redirect\_to (which just generates  
> window.location=…)

Thanks for the help 🙂
