Bug on NAMED ROUTES with last ACTIONPACK 3.0.4

52 views
Skip to first unread message

Nico_Arbogast

unread,
Feb 16, 2011, 1:37:31 PM2/16/11
to I18n Routing
Hi,

First, thank you for the gem.
It is really helpful and very efficient.

I had no problem working with it until I updated my gems to the latest
actionpack 3.0.4 tonight.
When launching the app on my local server, it broke and displayed an
error (see details below)

The error was coming from the "localization process" of a named route
in my route.rb file where I had the following code (which is perfectly
running and localized when working with actionpack 3.0.3):
<<
match 'named_route(/:param1(/:param2))' => "controller#action", :as
=> "name"
>>

Going back to actionpack 3.0.4 by writing the following in my Gemfile
fixed it instantly:
<<
gem 'actionpack', '3.0.3'
>>

I have no time right now to go into the actionpack change causing this
bug. I'm sorry.


SOME MORE DETAILS:
The error when launching the app locally:
<<
/opt/local/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/
route_set.rb:62:in `add_route': conditions may only include
[:auth_type, :gateway_interface, :path_translated, :remote_host, :remote_ident, :remote_user, :remote_addr, :server_name, :server_protocol, :accept, :accept_charset, :accept_encoding, :accept_language, :cache_control, :from, :negotiate, :pragma, :key?, :request_method, :request_method_symbol, :method, :method_symbol, :get?, :post?, :put?, :delete?, :head?, :headers, :fullpath, :forgery_whitelisted?, :forgery_whitelisted_with_deprecation?, :forgery_whitelisted_without_deprecation?, :media_type, :content_length, :xml_http_request?, :xhr?, :ip, :remote_ip, :server_software, :raw_post, :body, :form_data?, :body_stream, :reset_session, :session=, :session_options=, :GET, :query_parameters, :POST, :request_parameters, :authorization, :local?, :cookie_jar, :flash, :url, :scheme, :protocol, :ssl?, :raw_host_with_port, :host, :host_with_port, :port, :standard_port, :standard_port?, :port_string, :server_port, :domain, :subdomains, :subdomain, :request_uri, :filtered_parameters, :filtered_env, :parameters, :params, :path_parameters=, :symbolized_path_parameters, :path_parameters, :content_mime_type, :content_type, :accepts, :format, :formats, :format=, :negotiate_mime, :if_modified_since, :if_none_match, :not_modified?, :etag_matches?, :fresh?, :env, :script_name, :path_info, :query_string, :session, :session_options, :logger, :media_type_params, :content_charset, :script_name=, :path_info=, :options?, :trace?, :parseable_data?, :
[], :
[]=, :values_at, :referer, :referrer, :user_agent, :cookies, :path, :taguri=, :taguri, :to_yaml_style, :to_yaml_properties, :syck_to_yaml, :blank?, :present?, :presence, :duplicable?, :acts_like?, :try, :html_safe?, :with_options, :to_param, :to_query, :returning, :dclone, :to_yaml, :`, :to_json, :instance_values, :instance_variable_names, :copy_instance_variables_from, :as_json, :is_haml?, :meta_class, :share_examples_for, :shared_examples_for, :share_as, :describe, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :delay, :__delay__, :send_later, :send_at, :require_or_load, :require_dependency, :require_association, :load_dependency, :load, :require, :unloadable, :nil?, :===, :=~, :!
~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :public_method, :define_singleton_method, :__id__, :object_id, :to_enum, :enum_for, :gem, :silence_warnings, :enable_warnings, :with_warnings, :silence_stderr, :silence_stream, :suppress, :class_eval, :__called_from__, :expirable_memoize, :require_library_or_gem, :debugger, :breakpoint, :pretty_inspect, :suppress_warnings, :should, :should_not, :==, :equal?, :!, :!
=, :instance_eval, :instance_exec, :__send__, :i18n_locale]
(ArgumentError)
from /opt/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.4/lib/
action_dispatch/routing/route_set.rb:299:in `add_route'
from /opt/local/lib/ruby/gems/1.9.1/gems/i18n_routing-0.4.5/lib/
i18n_routing_rails3.rb:195:in `block in match'
from /opt/local/lib/ruby/gems/1.9.1/gems/i18n_routing-0.4.5/lib/
i18n_routing_rails3.rb:191:in `each'
from /opt/local/lib/ruby/gems/1.9.1/gems/i18n_routing-0.4.5/lib/
i18n_routing_rails3.rb:191:in `match'
>>

The error was coming from a named route in my route.rb file where I
had the following code (which is perfectly running and localized when
working with actionpack 3.0.3):
<<
match 'named_route(/:param1(/:param2))' => "controller#action", :as
=> "name"
>>

In my locales .yml files I have
<<
named_routes_path:
'named_route(/:param1(/:param2))' :
"translation(/:param1(/:param2))"
>>

Going back to actionpack 3.0.4 by writing the following in my Gemfile
fixed it instantly:
<<
gem 'actionpack', '3.0.3'
>>

NB: every other localized routes seemed to worked fine with actionpack
3.0.4:
With actionpack 3.0.4, when I changed my routes.rb to
<<
match 'named_route(/:param1(/:param2))', :to =>
"controller#action", :as => "name"
>>
this named route was "working" again (i.e. not breaking the app and
responding to url requests and displayed when raking routes) but it
was not translated anymore (i think the if condition in
your(i18n_routing_rails3) "match" method was not verified so it was
skipping this route when localizing).
Other localized routes where translated and working fine

Hope it helps someone!
For the moment, I will keep actionpack to version 3.0.3 to keep
everything stable when pushing my app to production.

Thanks again
Nico

Guillaume Luccisano

unread,
Feb 16, 2011, 1:49:25 PM2/16/11
to i18n-r...@googlegroups.com
Hi and thanks for the report.

Yeah I also though there was something strange with rails 3.0.4 and I didn't have the time to check this out.
I will try check and fix that soon.

Thanks !

2011/2/16 Nico_Arbogast <nic...@weezic.com>

pawelb

unread,
Apr 16, 2011, 11:42:45 PM4/16/11
to I18n Routing
I found a solution:

if you have in your routes something like this:

scope '/(:locale)', :locale => /en|pl|de/ do

..........

end

remove this bit :

:locale => /en|pl|de/

and it will work fine.

There is an issue with the i18n_routing_rails3.rb file, in version
0.4.6 , and to be specific it is line 195:

@set.add_route(*mapping.to_route)

the "mapping.to_route" returns this :

Rails 3.0.6

---
- !ruby/object:ActionDispatch::Routing::RouteSet::Dispatcher
controllers: {}

defaults: &id001
:controller: website/content
:action: contact
glob_param:
- :path_info: /(:locale)/blablabla
:locale: !ruby/regexp /en|pl|de/
- :locale: !ruby/regexp /en|pl|de/
- *id001
- pl_bobik
- true

Rails 3.0.3
---
- !ruby/object:ActionDispatch::Routing::RouteSet::Dispatcher
controllers: {}

defaults: &id001
:controller: website/content
:action: contact
glob_param:
- :path_info: /(:locale)/blablabla
:i18n_locale: pl
- :i18n_locale: pl
:locale: !ruby/regexp /en|pl|de/
- *id001
- pl_bobik
- true

in Rails 3.0.6 this bit:

- :path_info: /(:locale)/blablabla
:locale: !ruby/regexp /en|pl|de/

shouldn't have ":locale" inside of the Hash because ":locale" is not
allowed by Rack in a constraint parameter, but it does so it
crashes :)

I have checked Rails 3.0.7.rc2 and it is still the same so this is the
quickest fix possible :)

On Feb 16, 7:49 pm, Guillaume Luccisano
<guillaume.luccis...@gmail.com> wrote:
> Hi and thanks for the report.
>
> Yeah I also though there was something strange with rails 3.0.4 and I didn't
> have the time to check this out.
> I will try check and fix that soon.
>
> Thanks !
>
> 2011/2/16 Nico_Arbogast <nico...@weezic.com>

Guillaume Luccisano

unread,
Apr 17, 2011, 9:23:25 PM4/17/11
to i18n-r...@googlegroups.com
Thanks a lot for this analysis. I have some time to work on the gem right now, so hopefully a new version will be out soon :)

2011/4/16 pawelb <pawel....@gmail.com>

Guillaume Luccisano

unread,
Apr 17, 2011, 10:18:58 PM4/17/11
to i18n-r...@googlegroups.com
I just pushed a new version that should fix all of this :) Thanks for your post guys.
So to resume, the new version:
  • Handle empty translations
  • Re-enable the :locale constraints in Rack:Mount
  • Fix bug introduced by Rails 3.0.4

2011/4/17 Guillaume Luccisano <guillaume...@gmail.com>

Nicolas Arbogast | Weezic.com

unread,
Apr 18, 2011, 12:22:03 AM4/18/11
to i18n-r...@googlegroups.com, Guillaume Luccisano
Great 
Thanks a lot!

2011/4/18 Guillaume Luccisano <guillaume...@gmail.com>
Reply all
Reply to author
Forward
0 new messages