`add_route': conditions may only include [:...................] #1280

Closed
leehambley opened this Issue Aug 18, 2011 · 18 comments

Projects

None yet

6 participants

@leehambley

http://stackoverflow.com/questions/6618003/devise-routing-error-on-gem-update-rails-3-devise-omniauth

I've just come across this, I didn't find it tracked as an open bug.

$ bundle show | ack devise
  * devise (1.4.2)
$ bundle show | ack rails
  * coffee-rails (3.1.0.rc.5)
  * jquery-rails (1.0.13)
  * rails (3.1.0.rc5)
  * rails_config (0.2.4)
  * sass-rails (3.1.0.rc.5)

I'm not sure what the best course of action is

@nixme

I'm having this issue as well on Rails 3.1.0.rc6. Turning off the omniauth strategy in the model fixes it, but that's not really a solution. Seems the regexp route at https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L353 is the issue.

@josevalim
Plataformatec member

We could fix this by wrapping the :action key value below in a requirement hash. That said, the line:

https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L353

Should probably be:

:requirements => { :action => Regexp.union(...) }

Can someone check if this work and provide a patch?

@josevalim josevalim closed this in 1dd19c1 Aug 29, 2011
@nixme

Unfortunately, adding constraints results in the same issue. Seems rails doesn't like putting a constraint on the actions param specifically.

@josevalim
Plataformatec member

This is weird, very weird. Because it works fine for me and we don't have any failures on Devise test suite. Which rack-mount version are you using? Can you update it?

@nixme

Using rack-mount 0.8.2, this is the stack trace. If I change actions to anything else in devise/rails/routes.rb, it works but obviously isn't constraining the route correctly.

/usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/rack-mount-0.8.2/lib/rack/mount/route_set.rb:64:in `add_route': conditions may only include [:!, :!=, :!~, :<=>, :==, :===, :=~, :Factory, :GET, :POST, :[], :[]=, :__called_from__, :__id__, :__send__, :`, :accept, :accept_charset, :accept_encoding, :accept_language, :accepts, :acts_like?, :ai, :as_json, :auth_type, :authorization, :awesome_inspect, :awesome_print, :base_url, :blank?, :body, :body_stream, :breakpoint, :cache_control, :capture, :class, :class_eval, :clone, :content_charset, :content_length, :content_mime_type, :content_type, :cookie_jar, :cookies, :dclone, :debugger, :define_singleton_method, :delete?, :display, :domain, :dup, :duplicable?, :enable_warnings, :enum_for, :env, :eql?, :equal?, :etag_matches?, :expirable_memoize, :extend, :filtered_env, :filtered_parameters, :filtered_path, :flash, :forgery_whitelisted?, :forgery_whitelisted_with_deprecation?, :forgery_whitelisted_without_deprecation?, :form_data?, :format, :format=, :formats, :freeze, :fresh?, :from, :frozen?, :fullpath, :gateway_interface, :gem, :get?, :hash, :head?, :headers, :host, :host_with_port, :html_safe?, :if_modified_since, :if_none_match, :ignore_accept_header, :ignore_accept_header=, :in?, :initialize_clone, :initialize_dup, :inspect, :instance_eval, :instance_exec, :instance_of?, :instance_values, :instance_variable_defined?, :instance_variable_get, :instance_variable_names, :instance_variable_set, :instance_variables, :ip, :is_a?, :is_haml?, :key?, :kind_of?, :load, :load_dependency, :local?, :logger, :media_type, :media_type_params, :method, :method_symbol, :methods, :negotiate, :negotiate_mime, :nil?, :not_modified?, :object_id, :optional_port, :options?, :parameters, :params, :parseable_data?, :patch?, :path, :path_info, :path_info=, :path_parameters, :path_parameters=, :path_translated, :port, :port_string, :post?, :pragma, :presence, :present?, :private_methods, :protected_methods, :protocol, :psych_to_yaml, :psych_y, :public_method, :public_methods, :public_send, :put?, :query_parameters, :query_string, :quietly, :raw_host_with_port, :raw_post, :referer, :referrer, :remote_addr, :remote_host, :remote_ident, :remote_ip, :remote_user, :request_method, :request_method_symbol, :request_parameters, :require, :require_association, :require_dependency, :require_library_or_gem, :require_library_or_gem_with_deprecation, :require_library_or_gem_without_deprecation, :require_or_load, :reset_session, :respond_to?, :respond_to_missing?, :scheme, :script_name, :script_name=, :send, :server_name, :server_port, :server_protocol, :server_software, :session, :session=, :session_options, :session_options=, :silence, :silence_stderr, :silence_stream, :silence_warnings, :singleton_class, :singleton_methods, :ssl?, :standard_port, :standard_port?, :subdomain, :subdomains, :suppress, :suppress_warnings, :syck_to_yaml, :symbolized_path_parameters, :taguri, :taguri=, :taint, :tainted?, :tap, :tld_length, :tld_length=, :to_enum, :to_json, :to_param, :to_query, :to_s, :to_yaml, :to_yaml_properties, :to_yaml_style, :trace?, :trust, :try, :unloadable, :untaint, :untrust, :untrusted?, :url, :user_agent, :values_at, :with_options, :with_warnings, :xhr?, :xml_http_request?] (ArgumentError)
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/route_set.rb:344:in `add_route'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/mapper.rb:385:in `match'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/mapper.rb:1290:in `match'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/mapper.rb:1477:in `match'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:350:in `devise_omniauth_callback'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:197:in `block (4 levels) in devise_for'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:197:in `each'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:197:in `block (3 levels) in devise_for'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:359:in `with_devise_exclusive_scope'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:196:in `block (2 levels) in devise_for'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:296:in `block in devise_scope'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/mapper.rb:755:in `block in constraints'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/mapper.rb:630:in `scope'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/gems/actionpack-3.1.0.rc8/lib/action_dispatch/routing/mapper.rb:755:in `constraints'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:295:in `devise_scope'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:194:in `block in devise_for'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:177:in `each'
        from /usr/local/rvm/gems/ruby-1.9.2-p290@deathstar/bundler/gems/devise-7b1418be3b33/lib/devise/rails/routes.rb:177:in `devise_for'
@atd
atd commented Sep 3, 2011

Same problem here using rack-mount 0.8.3.

I am able to reproduce it with the following steps:

rails new dummy

Add to Gemfile:

gem 'social_stream-base', :git => 'https://github.com/ging/social_stream-base.git'
gem 'forgery'
bundle install

rails g social_stream:base:install

rake db:migrate
@josevalim
Plataformatec member

Do I need to have social_stream-base and forgery to reproduce the error? And I don't need devise at all?

@atd
atd commented Sep 3, 2011

Sure! social_stream-base depends on devise. I failed to reproduce it without the settings of the social_stream's generator.

@nixme

It's definitely forgery - must be one of its core class extensions. Removing it gets rid of the issue for me. Sorry for thinking it was on devise's end. Monkey-patching by gems is the culprit once again... ugh.

@leehambley
@leehambley
/Users/codebeaker/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:64:in `add_route': conditions may only include [:ignore_accept_header, :ignore_accept_header=, :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, :tld_length, :tld_length=, :url, :protocol, :raw_host_with_port, :host, :host_with_port, :port, :standard_port, :standard_port?, :optional_port, :port_string, :server_port, :domain, :subdomains, :subdomain, :filtered_parameters, :filtered_env, :filtered_path, :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, :scheme, :ssl?, :script_name=, :path_info=, :options?, :patch?, :trace?, :parseable_data?, :[], :[]=, :values_at, :referer, :referrer, :user_agent, :cookies, :base_url, :path, :psych_to_yaml, :to_yaml_properties, :to_yaml, :blank?, :present?, :presence, :acts_like?, :try, :in?, :html_safe?, :duplicable?, :is_haml?, :to_json, :instance_values, :instance_variable_names, :as_json, :with_options, :to_param, :to_query, :`, :pretty_print, :pretty_print_cycle, :pretty_print_instance_variables, :pretty_print_inspect, :Factory, :friendly_id?, :unfriendly_id?, :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, :psych_y, :y, :silence_warnings, :enable_warnings, :with_warnings, :silence_stderr, :silence_stream, :suppress, :capture, :silence, :quietly, :class_eval, :pretty_inspect, :debugger, :breakpoint, :binding_n, :require_library_or_gem, :require_library_or_gem_with_deprecation, :require_library_or_gem_without_deprecation, :suppress_warnings, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__] (ArgumentError)
    from /Users/codebeaker/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/route_set.rb:344:in `add_route'
    from /Users/codebeaker/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/mapper.rb:385:in `match'
    from /Users/codebeaker/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/mapper.rb:1290:in `match'
    from /Users/codebeaker/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/action_dispatch/routing/mapper.rb:1477:in `match'

I'm seeing that under the latest devise 1.4.4. This is something of a problem. Looks like that change in SHA1:1dd19c1 didn't cure this, because :constraints isn't allowed to contain :action.

(Edit: I'm also using Forgery, and have opened sevenwire/forgery#35 as a feeler to see if the maintainer is interested in a re-factor (I started work, but it's really a mess to try and refractor all of that stuff))

@nixme what is forgery monkey patching that breaks this? (code link?)

@nate

I just released forgery 0.4.0, could you give it a try and see if it fixes the issue for you? Sorry for the trouble!

@nate

I've just tried this with forgery-0.4.0 and it appears to work now. Can anyone else confirm?

@nate

Actually, make that forgery-0.4.1. :)

@nixme

Confirmed that forgery-0.4.1 fixes the issue on our end. Thanks for the quick turnaround @nate !

@leehambley
@atd
atd commented Sep 4, 2011

I confirm too, thank you @nate !

@sheerun

I actually don't use forgery and have the same issue. Probably some other gem is messing up.
My solution was to comment out following from lib/devise/rails/routes.rb (monkeypatch)

:constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },

Hope it helps someone.

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