This project is archived and is in readonly mode.

#4874 ✓resolved
José Valim

Calling mount and resource inside the router makes mount stop working

Reported by José Valim | June 16th, 2010 @ 05:37 PM | in 3.0.2

Example:

DeviseMountError::Application.routes.draw do |map|
  class MySinatraBlogApp < Sinatra::Base
    get "/archives" do
      "my old posts"
    end
  end
  mount MySinatraBlogApp, :at => '/blog'

  resource :user
end

If we access "/blog/archives" it does not work unless we comment the resource :user line. Reproducible with Rails 3 beta 4.

Comments and changes to this ticket

  • José Valim

    José Valim June 17th, 2010 @ 12:51 PM

    • Assigned user changed from “José Valim” to “josh”

    Hey Josh, could you please take a look at this issue? I pushed a failing test here:

    http://github.com/rails/rails/commit/7ba756281ac193e53cabba3ada75f1...

    I've tried to debug it but could not find the reason, thanks!

  • Damien MATHIEU
  • Andrew White

    Andrew White June 17th, 2010 @ 03:10 PM

    This is a weird one - the resource call can be before or after the mount and it works if the resource call is nested inside a resources call but not inside a namespace. I've tried renaming the resource method but that didn't work. Inspecting the scope before and after the resource call shows a bunch of nil values in the scope but they're exactly the same as a resources call.

    If you turn off all the routes using :only => [], then it works. You can also make a resources call generate the error by doing :only => [:show, :new, :create]. I think the error must be in rack-mount somewhere.

  • josh

    josh June 22nd, 2010 @ 05:37 PM

    Works for me.

    Make sure you're using Sinatra 1.x, needs to include this commit http://github.com/sinatra/sinatra/commit/f9a792396ca6172e983b7eb4d7...

  • Andrew White

    Andrew White June 22nd, 2010 @ 06:56 PM

    Still getting the problem here when using Sinatra 1.0. It's triggered by defining a singleton resource at the top level. If you nest the resource then it works. However namespacing the resource doesn't fix it.

    I followed the call down into Rack::Mount with ruby-debug but didn't follow it any further. I'll do some more investigation tonight.

  • Andrew White

    Andrew White June 23rd, 2010 @ 11:24 AM

    It looks as though the problem is somewhere in Rack::Mount::Analysis::Splitting.

    This is what I get for @recognition_key_analyzer.possible_keys when using resource:

    [
      {path_info[0]=>"/blog"}, 
      {:request_method=>/POST/, path_info[0]=>"/user"}, 
      {:request_method=>/GET/, path_info[0]=>"/user/new"}, 
      {:request_method=>/GET/, path_info[0]=>"/user"}, 
      {:request_method=>/PUT/, path_info[0]=>"/user"}, 
      {:request_method=>/DELETE/, path_info[0]=>"/user"}, 
      {:request_method=>/GET/, path_info[0]=>"/user/edit"}, 
      {path_info[0]=>"/rails/info/properties", path_info[1]=>"\000"}
    ]
    

    And this is what I get for @recognition_key_analyzer.possible_keys when using resources:

    [
      {path_info[0]=>"blog"}, 
      {:request_method=>/GET/, path_info[0]=>"users"}, 
      {:request_method=>/POST/, path_info[0]=>"users"}, 
      {:request_method=>/GET/, path_info[0]=>"users", path_info[1]=>"new"}, 
      {:request_method=>/GET/, path_info[0]=>"users", path_info[1]=>/\A([^\/.?]+)\Z/}, 
      {:request_method=>/PUT/, path_info[0]=>"users", path_info[1]=>/\A([^\/.?]+)\Z/}, 
      {:request_method=>/DELETE/, path_info[0]=>"users", path_info[1]=>/\A([^\/.?]+)\Z/}, 
      {:request_method=>/GET/, path_info[0]=>"users", path_info[1]=>/\A([^\/.?]+)\Z/, path_info[2]=>"edit"}, 
      {path_info[0]=>"rails", path_info[1]=>"info"}, path_info[2]=>"properties", path_info[3]=>"\000"
    ]
    

    I'm not sure whether it's significant, but it looks like it might be.

  • Andrew White

    Andrew White June 23rd, 2010 @ 12:06 PM

    Josh, I think I've identified the problem. When you have a small number of routes then '/' may be dropped from the separator pattern because it doesn't appear enough to put it in the upper quartile. Put in a few more routes and it then starts working. Shouldn't '/' always be in the separator pattern?

  • DHH

    DHH June 25th, 2010 @ 12:03 AM

    • Milestone cleared.
  • José Valim

    José Valim June 26th, 2010 @ 12:30 AM

    • Milestone cleared.
    • State changed from “open” to “resolved”
    • Assigned user changed from “josh” to “Andrew White”

    Fixed with the commit above applied to rack-mount.

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “High”

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>

Pages