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.

Routing problem in rails 3 rc

#5399

I have route like this

match 'test/:param1/:param2' => 'welcome#index', :as => 'random_welcome'

the i tried to use it

random_welcome_url :param1 => 'test', :param2 => 'test'

and got error

No route matches {:controller=>"welcome", :action=>"index", :param1=>"test", :param2=>"test"}

but opening http://localhost:3000/test/test/test works perfect

full error log attached.

Reported by bug.odesk (at gmail) · August 18th, 2010 @ 03:04 AM

State: resolved
Milestone: 3.0.2
Assigned to: josh josh
Importance: High

Activity

  1. bug.odesk (at gmail)
    bug.odesk (at gmail)

    Forgot to say that i tested on this route on empty project and got same error.

    August 18th, 2010 @ 03:05 AM

  2. bug.odesk (at gmail)
    bug.odesk (at gmail)
    • Title changed from Routing problem to Routing problem in rails 3 rc

    August 18th, 2010 @ 03:05 AM

  3. Andrew White
    Andrew White
    • State changed from new to invalid
    • Assigned user set to Andrew White
    • Importance changed from to Low

    Works for me:

    # config/routes.db
    Testapp::Application.routes.draw do
      match 'test/:param1/:param2' => 'welcome#index', :as => 'random_welcome'
    end
    
    # script/rails c
    Loading development environment (Rails 3.0.0.rc)
    >> app.random_welcome_url(:param1 => 'test', :param2 => 'test')
    => "http://www.example.com/test/test/test"
    

    The error log doesn't mention random_welcome_url - it seems to be using download_request_url. I also notice that you're using Haml - can you try with a plain ERb template?

    August 18th, 2010 @ 01:55 PM

  4. bug.odesk (at gmail)
    bug.odesk (at gmail)

    I uploaded empty project with one route and few controllers. Can you please check if

    download_request_url :file_token => "aaaaaa33", :file_name => "test.gif"
    

    works for you.

    http://github.com/slbug/testapp/zipball/master

    August 18th, 2010 @ 02:25 PM

  5. Andrew White
    Andrew White

    No need to check it now you've given me the actual code you were using - periods are no accepted by default in params so that /resource/:id(.:format) works. All you need to do is relax the constraint and it'll start working:

    match 'dl/:file_token/:file_name' => 'test#download_request', :as => 'download_request', :file_name => /[^\/]+/
    

    August 18th, 2010 @ 02:40 PM

  6. bug.odesk (at gmail)
    bug.odesk (at gmail)

    Thanks now it works, but when i trying to add regexp for :file_token it fails again.

    match 'dl/:file_token/:file_name' => 'test#download_request', :as => 'download_request', :file_token => /[a-f0-9]{32}/, :file_name => /[^\/]+/
    
    download_request_url :file_token => "85b3a01dd29b77579b17a2fe179bd9ba", :file_name => "test.gif"
    

    Can you tell where is error?

    August 18th, 2010 @ 02:53 PM

  7. Andrew White
    Andrew White
    • Milestone cleared.
    • State changed from invalid to open
    • Importance changed from Low to High

    This is a bug in the bundled Regin Regexp parser in Rack::Mount (which underlies the Rails 3 router). It's fixed in Regin 0.3.6 but Rack::Mount is only bundled with Regin 0.3.5.

    In the meantime you can specify the constraint using a repeated block, e.g:

      :file_token = /(?:[a-f0-9]{8}){4}/
    

    Slightly hackish, but it does the job.

    August 18th, 2010 @ 03:49 PM

  8. bug.odesk (at gmail)
  9. Jeremy Kemper
    Jeremy Kemper
    • Assigned user changed from Andrew White to josh

    August 19th, 2010 @ 05:22 PM

  10. Andrew White
  11. Jeremy Kemper