Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

:constraints option in router won't accept an object

#4904

I have a module:

module LoggedInConstraint
  def self.matches?(request)
    request.session[:user_id]
  end
end

The following snippet works as expected:

constraints LoggedInConstraint do
  root :to => 'quizzes#index'
end

But this does not:

root :to => 'quizzes#index', :constraints => LoggedInConstraint

It fails with:

actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:161:in `constraints': undefined method `reject' for LoggedInConstraint:Module (NoMethodError)

This occurs even though it's explicitly demonstrated in the edge routing guide:

http://guides.rails.info/routing.html#advanced-constraints

So if this is a won't fix, the edge guides should be updated to remove the example.

Reported by PreciousBodilyFluids · June 19th, 2010 @ 05:41 AM

State: resolved
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. PreciousBodilyFluids
    PreciousBodilyFluids

    I wrote a test to cover this case, but the test suite won't run with it. It's attached anyhow.

    It fails with:

    
    /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:161:in `constraints': undefined method `reject' for TestRoutingMapper::IpRestrictor:Class (NoMethodError)
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:101:in `conditions'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:44:in `to_route'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:211:in `match'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:369:in `match'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:735:in `match'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:287:in `map_method'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/mapper.rb:239:in `get'
        from ./test/dispatch/routing_test.rb:71
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/route_set.rb:215:in `instance_exec'
        from /home/chris/rails/actionpack/lib/action_dispatch/routing/route_set.rb:215:in `draw'
        from ./test/dispatch/routing_test.rb:17
        from ./test/abstract_unit.rb:188:in `stub_controllers'
        from ./test/dispatch/routing_test.rb:15
        from /home/chris/rails/activesupport/lib/active_support/dependencies.rb:208:in `load'
        from /home/chris/rails/activesupport/lib/active_support/dependencies.rb:208:in `load'
        from /home/chris/rails/activesupport/lib/active_support/dependencies.rb:198:in `load_dependency'
        from /home/chris/rails/activesupport/lib/active_support/dependencies.rb:554:in `new_constants_in'
        from /home/chris/rails/activesupport/lib/active_support/dependencies.rb:198:in `load_dependency'
        from /home/chris/rails/activesupport/lib/active_support/dependencies.rb:208:in `load'
        from /home/chris/.rvm/gems/ree-1.8.7-2010.02@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
        from /home/chris/.rvm/gems/ree-1.8.7-2010.02@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
        from /home/chris/.rvm/gems/ree-1.8.7-2010.02@global/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
    rake aborted!
    Command failed with status (1): [/home/chris/.rvm/rubies/ree-1.8.7-2010.02/...]
    

    June 19th, 2010 @ 06:23 AM

  2. Andrew White
    Andrew White
    • Tag set to rails 3.0, actiondispatch, constraints, patch, routing

    Attached patch fixes the problem - thanks for the test case.

    June 19th, 2010 @ 08:57 PM

  3. Andrew White
    Andrew White
    • Assigned user set to Jeremy Kemper

    June 19th, 2010 @ 09:01 PM

  4. Repository