Coder Social home page Coder Social logo

Comments (5)

lightbe avatar lightbe commented on July 18, 2024

Is there another version of this gem that works with Rails 4? I still cannot get this working.

from routing-filter.

kreintjes avatar kreintjes commented on July 18, 2024

I have exactly the same problem with 0.4.0.pre in combination with a Rails 4 app. Both the standard locale filter as well as a custom filter do not work properly. The locale is read out from URLs (meaning params[:locale] is properly set), but unfortunately it is not included automatically anymore in URLs generated within Rails.

from routing-filter.

lightbe avatar lightbe commented on July 18, 2024

A few days ago I rewrote my routing logic to use what Rails 4 provided and removed the gem. I had another issue with my custom error pages not working anymore with I18n that was more critical for me to correct. At least I was able to get the routing working without the gem. I ended up rewriting my custom error pages in HTML and putting them in the public folder. By naming them as 404.en.html, 404.fr.html, etc. the correct page is displayed depending on the locale.

I will leave the issue open for now just in case I may decide to use this gem again.

from routing-filter.

kreintjes avatar kreintjes commented on July 18, 2024

This issue seems to be the same issue as #47. The monkey patch there can help you (temporarily) fix this problem. However, I think this is not ideal.

May I ask how you solved this with the solutions provided by Rails 4?

from routing-filter.

lightbe avatar lightbe commented on July 18, 2024

I removed config.exceptions_app from application.rb since it appears that it has been deprecated. This is what I used for my custom error pages.

Here is the scope statement in routes.rb I'm using.

scope "(/:locale)", locale: /#{I18n.available_locales.join("|")}/ do
my routes here
end

This scope statement includes the locale in the routes (i.e. /en, /fr, ) but allows the locale to default to en if no locale is in the URL. For example http://mydomain.com/home and http://mydomain.com/en/home will both display the English version of the view. You will get the same results by using the following.

scope "(/:locale)" do
my routes here
end

The only difference I know of is that the first scope statement will display the locales when you do rake routes to list your defined routes. The second one does not. There are probably other differences that I am not aware of.

I then created separate error pages for each locale using HTML and placed them in the public folder. I did not have to add any code to lib/tasks like earlier versions required starting with Rails 2. I guess the code that was required is now included in Rails 4. As I mentioned when I get errors while using the English version of the website the error file nnn.en.html is displayed. If I get and error using the French version nnn.fr.html is displayed, etc.

from routing-filter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.