This project is archived and is in readonly mode.

#4904 ✓resolved
PreciousBodilyFluids

:constraints option in router won't accept an object

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

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.

Comments and changes to this ticket

  • PreciousBodilyFluids

    PreciousBodilyFluids June 19th, 2010 @ 06:23 AM

    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/...]
    
  • Andrew White

    Andrew White June 19th, 2010 @ 08:57 PM

    • Tag set to rails 3.0, actiondispatch, constraints, patch, routing

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

  • Andrew White

    Andrew White June 19th, 2010 @ 09:01 PM

    • Assigned user set to “Jeremy Kemper”
  • Repository

    Repository June 19th, 2010 @ 11:19 PM

    • State changed from “new” to “resolved”

    (from [65ce3d12971afd15de6ea22a2fc5af3ba1faf124]) Accept an object for :constraints option [#4904 state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/65ce3d12971afd15de6ea22a2fc5af...

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages