Jump to content

The ultimate community for Ruby on Rails developers.


Having Problems with Custom Error Pages using I18n

custom error pages I18n routing localization rails3 rails 4

  • Please log in to reply
3 replies to this topic

#1 lightbecorp



  • Members
  • 10 posts

Posted 18 October 2013 - 02:20 PM

I have a Rails 3.2.13 application that has been localized for English and French.  When I first localized the application I was using the routing-filter gem.  When I started working on a Rails 4.0.0 application I attempted to use the 4.0 beta version of the gem but could not get it to work.  I decided to rewrite the routing of my Rails 3.2.13 applications to use the built-in I18n routing functionality.  My applications use custom error pages using Self.routes.  Everything in my application is working properly except for the custom error pages.  For example if I get a 404 error instead of the correct custom error page for the locale displaying it appears that the locale value is changed to 404 and attempts to display the landing page looking for translations for locale 404.


I have done a lot of web searching since yesterday but have not found any examples of how to do this using I18n.  The 3.2.13 routing-filter gem took care of this.

Here is the link to Stack Overflow where I posted the question.  It includes details of exactly what is happening and the code I'm attempting to execute.



Any help would be appreciated.  I will keep looking.

#2 lightbecorp



  • Members
  • 10 posts

Posted 07 November 2013 - 06:32 PM

I never got any responses here on on my initial question on Stack Overflow.  I decided to abandon this process and see if I could find a way to do this in the public folder.  It was difficult to find documentation for this as well.  I decided to post another question about this a couple of weeks ago.



Unfortunately I did not hear anything again.  I guess there are not a lot of people localizing Rails applications.  I ended up making a guess and finding a solution that works well.  I detail what I did in the link below.  It appears that config.exceptions_app = self.routes has been deprecated.  At least in my situation it was completely ignored.  Thankfully it is a lot easier to do custom error pages using I18n in Rails 4.

#3 gorrillamcd



  • Members
  • 4 posts
  • LocationGuadalajara, Mexico

Posted 08 November 2013 - 10:01 PM

Hey LightBeCorp, thanks for coming back with the results. I'm going to be building an app soon that will need i18n and it'd be super useful to know if you have a link to the complete solution for rails 4.

#4 lightbecorp



  • Members
  • 10 posts

Posted 18 March 2014 - 02:52 PM

I just saw the response from you gorrillamcd. I found out with Rails 4 that it is a lot easier to implement custom error pages.  You don't have to do any special configuration at all.  Just create a separate error page for each locale in the public folder.  For example I have four locales in one of my Rails 4 applications.  For error 404 I have 404.en.html, 404.fr.html, 404.pt.html and 404.es.html.  I have done the same for error 500.  I could not find documentation for this.  I just decided to try it and see if it worked.

I saw something like this on Stack Overflow for Rails 2 but the configuration was so complicated that I did not bother to try it.

Also tagged with one or more of these keywords: custom error pages, I18n, routing, localization, rails3, rails 4

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users