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.

"root" doesn't work as advertised in new routing DSL

#3605
# The following produces No route matches {:controller=>"welcome"}
ruby script/generate controller welcome index
sed -i -e 's/# root/root/' config/routes.rb
sed -i -e 's/assert true/get root_path/' test/functional/welcome_controller_test.rb
rake db:migrate
rake test:functionals

# Adding an action produces: No route matches {:controller=>"welcome", :action=>"/"}
sed -i -e 's/welcome/welcome#index/' config/routes.rb
rake test:functionals

Reported by Sam Ruby · December 21st, 2009 @ 08:21 PM

State: resolved
Milestone: 3.0.2
Assigned to: DHH DHH
Importance: none

Activity

  1. DHH
    DHH
    • State changed from open to resolved

    Fixed the documentation instead. Allowing the :to to use a string to signify the controller would clash with the regular use of :to that uses a symbol for an action.

    December 22nd, 2009 @ 12:56 AM

  2. Sam Ruby
    Sam Ruby
    • State changed from resolved to open
    • Assigned user changed from josh to DHH

    Sorry to reopen this on you, but the last two lines of the script above shows that adding #index doesn't work either. I'm flexible on what the syntax is, but I would like to have one that works.

    December 22nd, 2009 @ 03:26 AM

  3. DHH
    DHH
    • State changed from open to resolved

    Works for me. Added a test to the suite testing root specifically and that works too. Think it must be something in your test script.

    December 22nd, 2009 @ 05:51 AM

  4. Sam Ruby
    Sam Ruby

    My ENTIRE script is posted at the top of this ticket. Now that you have committed a change to the generated routes.rb, the last two lines are not necessary.

    It can be 100% reproduced with an new and otherwise completely empty project.

    In words, the script is as follows:

    1) Generate a controller named welcome with a single action, named index.
    2) Uncomment out the root line in config/routes.rb
    3) Change "assert true" to "get root_path" in test/functional/welcome_controller_test.rb
    4) Execute "rake db:migrate"
    5) Execute "rake test:functionals"

    If there is something wrong in that five step test script above, please tell me what it might be. Otherwise, I suspect that something about the unit test environment doesn't match how Rails is actually run.

    A complete set of output is included below:

    $ rake test:functionals
    (in /home/rubys/tmp/testapp)
    DEPRECATION WARNING: ActiveSupport::DeprecatedCallbacks has been deprecated in favor of ActiveSupport::Callbacks. (called from included at /home/rubys/tmp/testapp/vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:7)
    Loaded suite /usr/lib/ruby/1.8/rake/rake_test_loader
    Started
    E
    Finished in 0.108231 seconds.
    
      1) Error:
    test_the_truth(WelcomeControllerTest):
    ActionController::RoutingError: No route matches {:controller=>"welcome", :action=>"/"}
        /test/functional/welcome_controller_test.rb:6:in `test_the_truth'
    
    1 tests, 0 assertions, 0 failures, 1 errors
    rake aborted!
    Command failed with status (1): [/usr/bin/ruby1.8 -I"/home/rubys/tmp/testap...]
    
    (See full trace by running task with --trace)
    

    I will seek somebody else to reproduce this, and if they can, will ask them to reopen the ticket.

    December 22nd, 2009 @ 12:18 PM

  5. DHH
    DHH

    Your functional test is the problem. You can't use paths for the get there. That's what you do in integration tests. In functional, you'd do get :index.

    I've verified that root :to => "welcome#index" works fine in the browser as well.

    December 22nd, 2009 @ 03:31 PM

  6. Jeremy Kemper