# How to add a dynamic data in erro pages

**URL:** <https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324>\
**Category:** Rails\
**Created:** [October 20, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324 "2008-10-20T12:03:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [October 20, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324/1 "2008-10-20T12:03:13Z")

</div>

Hi,

In my application i had two error pages for 500 and 404 error.  
500.html and 404.html  
when someting went wrong this pages is called. but this pages are  
static pages if i want to add some dynamic data how i can add in it?  
ex.  
say user A’s session going on and he click some bad url or  
something so  
i wan t show user A’s name and other data n 500.404.html page.

Please help me to find this? and find how to configure this error  
pages in application

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [October 20, 2008, 12:37pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324/2 "2008-10-20T12:37:49Z")

</div>

The pages are located in public/. You could use your own error  
controller. Simply remove 500 and 404.html in public/ and set the  
correct routes to match your error controller.

lg // andreas

–  
DynamicDudes

Lightweight Ruby on Rails application development  
[http://dynamicdudes.com](http://dynamicdudes.com)  
[http://rubyphunk.com](http://rubyphunk.com)

On Mon, Oct 20, 2008 at 12:03 PM, Sunny B.

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [October 20, 2008, 12:52pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324/3 "2008-10-20T12:52:18Z")

</div>

But how can i add a dynamic data in it?  
can you tell me how to set in my own directory? please

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [October 20, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324/4 "2008-10-20T13:53:31Z")

</div>

Thanks Andreas. This is very helpful for me.

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [October 20, 2008, 1:33pm UTC](https://www.ruby-forum.com/t/how-to-add-a-dynamic-data-in-erro-pages/151324/5 "2008-10-20T13:33:37Z")

</div>

I think I was pointing you in the wrong direction. If you want dynamic  
data in your 500 error page you will need to rename public/500.html  
into 500.erb and add

def rescue\_action\_in\_public(exception)  
render :file =\> ‘public/500.erb’  
end

to your application.rb. This will render the 500 page based on erb…  
Lets say you have a current\_user method which points to the currently  
logged in user you could write:

Dear, \<%= current\_user.name %\>.  
An error has occured… Please stay tuned…

Hope this helps?!

lg // andreas

–  
DynamicDudes

Lightweight Ruby on Rails application development  
[http://dynamicdudes.com](http://dynamicdudes.com)  
[http://rubyphunk.com](http://rubyphunk.com)

On Mon, Oct 20, 2008 at 12:52 PM, Sunny B.
