Hope I've got the right gem - apologies in advance if not.
In my Rails app, I have some routes defined like this:
resources :blogs do
scope :module => :blogs do
resources :posts
end
end
I am trying to have a URL like /blogs/1/posts/2, which routes to the Blogs::PostsController.
Trying to get a URL for a posts path results in an exception:
Loading development environment (Rails 3.2.12)
irb(main):001:0> include ActionDispatch::Routing::UrlFor; include Rails.application.routes.url_helpers
=> Object
irb(main):002:0> url_for(:controller => 'blogs/posts', :action => :index)
ActionController::RoutingError: No route matches {:controller=>"blogs/posts"}
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:533:in `raise_routing_error'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:529:in `rescue in generate'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:521:in `generate'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:562:in `generate'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:587:in `url_for'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/url_for.rb:148:in `url_for'
from (irb):2
from /path/to/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /path/to/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /path/to/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
route_set.rb:529 is a rescue for Journey::Router::RoutingError, so I commented that out (sorry, I'm not very good with the ruby debugger yet). This gave me a new trace:
Loading development environment (Rails 3.2.12)
irb(main):001:0> include ActionDispatch::Routing::UrlFor; include Rails.application.routes.url_helpers
=> Object
irb(main):002:0> url_for(:controller => 'blogs/posts', :action => :index)
Journey::Router::RoutingError: Journey::Router::RoutingError
from /path/to/gems/journey-1.0.4/lib/journey/formatter.rb:46:in `generate'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:521:in `generate'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:562:in `generate'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:587:in `url_for'
from /path/to/gems/actionpack-3.2.12/lib/action_dispatch/routing/url_for.rb:148:in `url_for'
from (irb):2
from /path/to/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /path/to/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /path/to/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I looked at formatter.rb but it's greek to me. I'd try to help with a patch if someone could point me in the right direction.
By the way, defining my route this way instead, without the outer resource wrapper, works fine:
scope :module => :blogs do
resources :posts
end
...but that's not what I want to do, because then the URL is like /posts/2 instead of /blogs/1/posts/2.
Hope I've got the right gem - apologies in advance if not.
In my Rails app, I have some routes defined like this:
I am trying to have a URL like
/blogs/1/posts/2
, which routes to theBlogs::PostsController
.Trying to get a URL for a
posts
path results in an exception:route_set.rb:529
is a rescue forJourney::Router::RoutingError
, so I commented that out (sorry, I'm not very good with the ruby debugger yet). This gave me a new trace:I looked at
formatter.rb
but it's greek to me. I'd try to help with a patch if someone could point me in the right direction.By the way, defining my route this way instead, without the outer
resource
wrapper, works fine:...but that's not what I want to do, because then the URL is like
/posts/2
instead of/blogs/1/posts/2
.