francesc / rails-translate-routes

MIT License
147 stars 50 forks source link

Gem breaks Rails.application.routes.url_helpers #10

Closed jerefrer closed 12 years ago

jerefrer commented 12 years ago

In some models i'm using

Rails.application.routes.url_helpers.articles_path

But after installing the gem I had this error :

undefined method `articles_path' for #<Module:0x7f744fbaaa70>
francesc commented 12 years ago

Try to use: Rails.application.routes.url_helpers.articles_en_path

jerefrer commented 12 years ago

Yep it's working.

But this way the route will always be the english one won't it ?

Aren't we losing the main point of your gem (transparent simplicity !) if we need to specify the language ?

francesc commented 12 years ago

Hey,

In a model you can access the I18n.locale so you can make a work-around:

eval("Rails.application.routes.urlhelpers.articles#{I18n.locale.to_s}_path")

I agree it's not the best way, but take into account that 99% of time you don't use url helpers on models so I thinks it's a worth price to pay being able to have the other features of the gem.

dgilperez commented 10 years ago

Ouch! Got hit by this after upgrading to Rails 4 (everything was working nice on Rails 3.2). This is not very obvious and was kind of hard to debug ... do you think we can reopen this issue and work on a fix?

My main use case is for service objets (PORO) connecting to external APIs (payment processors, for instance).