Issue when wrapping localized block in scope (Rails 3.1, Ruby 1.9.2) #30

Open
ncri opened this Issue Oct 16, 2011 · 12 comments

Projects

None yet

6 participants

@ncri
ncri commented Oct 16, 2011

When I do

scope "(:locale)", :locale => /(fr-CH)/ do
  localized do
      match '/inserieren' => 'site#advertise', :as => :advertise
  end
end

and then go to /fr-CH/inserieren

I get this error:

NoMethodError: undefined method `locale' for #ActionDispatch::Request:0x007fc222715bb0


rack-mount (0.8.3) lib/rack/mount/code_generation.rb:543:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:531:in `call'
oa-core (0.2.6) lib/omniauth/strategy.rb:44:in `call!'
oa-core (0.2.6) lib/omniauth/strategy.rb:30:in `call'
oa-core (0.2.6) lib/omniauth/builder.rb:30:in `call'
newrelic_rpm (3.1.1) lib/new_relic/rack/browser_monitoring.rb:18:in `call'
sass (3.1.7) lib/sass/plugin/rack.rb:54:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.2) lib/rack/etag.rb:23:in `call'
rack (1.3.2) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.2) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.2) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/cookies.rb:326:in `call'
activerecord (3.1.0) lib/active_record/query_cache.rb:62:in `call'
activerecord (3.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.0) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.2) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.2) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.2) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.2) lib/rack/lock.rb:15:in `call'
rack-rewrite (1.0.2) lib/rack/rewrite.rb:19:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.0) lib/rails/engine.rb:455:in `call'
railties (3.1.0) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.0) lib/rails/rack/log_tailer.rb:14:in `call'
thin (1.2.11) lib/thin/connection.rb:84:in `block in pre_process'
thin (1.2.11) lib/thin/connection.rb:82:in `catch'
thin (1.2.11) lib/thin/connection.rb:82:in `pre_process'
thin (1.2.11) lib/thin/connection.rb:57:in `process'
thin (1.2.11) lib/thin/connection.rb:42:in `receive_data'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in `run'
thin (1.2.11) lib/thin/backends/base.rb:61:in `start'
thin (1.2.11) lib/thin/server.rb:159:in `start'
rack (1.3.2) lib/rack/handler/thin.rb:13:in `run'
rack (1.3.2) lib/rack/server.rb:265:in `start'
railties (3.1.0) lib/rails/commands/server.rb:70:in `start'
railties (3.1.0) lib/rails/commands.rb:54:in `block in <top (required)>'
railties (3.1.0) lib/rails/commands.rb:49:in `tap'
railties (3.1.0) lib/rails/commands.rb:49:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
@ncri
ncri commented Oct 16, 2011

Trying to workaround doing this:

localized do
  match '(:locale/)inserieren' => 'site#advertise', :as => :advertise
end

also doesn't work, as i18n_routing doesn't add translations for the routes with optional locale param.

@sauberia
sauberia commented Nov 9, 2011

I'm having the exact same issue with Rails 3.0.10

@rogercampos

I'm also having this issue, rails 3.0.9

@daemaechi

I'm facing this problem with rails 3.0.8...

Any workaround?

@ncri
ncri commented Dec 5, 2011

I ended up making my own localized_route helper, not using I18n_routing...

@sauberia
sauberia commented Dec 5, 2011

I also gave up on i18n_routing.

@rogercampos

What do you use instead?

@sauberia
sauberia commented Dec 5, 2011

I can't vouch for the quality of my solution but here it is anyway...

Extract of my routes file

Locales

Method missing to call localised named route

@ncri
ncri commented Dec 5, 2011

For translated named routes I use a helper I made myself:

Helper: https://gist.github.com/1435458
Some routes: https://gist.github.com/1435467

Basically I'm having base locales which don't have the locale in the url path but are set from user locales and/or domain.
Only url prefix locales have the locale in the route.

For resource routes I18n_routing works okay for me.

@ncri
ncri commented Dec 6, 2011

Oh, and here the corresponding route translations for a locale: https://gist.github.com/1437306

@theplaz
theplaz commented Mar 17, 2013

I am having the same problem.
When I run rake routes I get

en_cart GET /(:locale)/cart(.:format) orders#show {:i18n_locale=>"en", :locale=>/en-US|en-GB|de-DE/}
de_cart GET /(:locale)/warenkorb(.:format) orders#show {:i18n_locale=>"de", :locale=>/en-US|en-GB|de-DE/}
cart GET (/:locale)/cart(.:format) orders#show {:locale=>/en-US|en-GB|de-DE/}
en_checkout POST /(:locale)/checkout/:id(.:format) orders#checkout {:i18n_locale=>"en", :locale=>/en-US|en-GB|de-DE/}
de_checkout POST /(:locale)/checkout/:id(.:format) orders#checkout {:i18n_locale=>"de", :locale=>/en-US|en-GB|de-DE/}
checkout POST (/:locale)/checkout/:id(.:format) orders#checkout {:locale=>/en-US|en-GB|de-DE/}

It seems to be that the / is on the wrong side of the parenthesis. What does that mean? How can I fix it?

@macbury
macbury commented Apr 26, 2013

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment