Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing 'rake routes' for a mountable Rails 3.1 engine

Tags:

I'm working on a mountable engine for use with Rails 3.1, and I want to list the engine's routes.

I created the engine using:

$ rails plugin new rails_blog_engine --mountable 

And edited the 'test/dummy/config/routes' file to read:

Rails.application.routes.draw do   mount RailsBlogEngine::Engine => "/blog" end 

...and 'config/routes' to read:

RailsBlogEngine::Engine.routes.draw do   resources :posts end 

I want to list the routes generated for ':posts', but it's not clear how I can do this. When I run 'rake app:routes', I get only the "/blog" route:

$ rake app:routes rails_blog_engine    /blog    {:to=>RailsBlogEngine::Engine} 

When I run 'rake routes', I get an error:

$ rake routes rake aborted! Don't know how to build task 'routes' 

How can I see the routes for ':posts'? Can I do this without rewriting the relevant rake tasks?

like image 277
emk Avatar asked Sep 15 '11 13:09

emk


2 Answers

In case people are missing it in the comments, as of Rails 3.2.2, you can now use

$ rake app:routes 
like image 50
maček Avatar answered Jan 03 '23 10:01

maček


If you copy code from the standard Rails 3.1.0 rake routes task into your Rakefile, and change the top part to read:

task :routes => 'app:environment' do   Rails.application.reload_routes!   all_routes = RailsBlogEngine::Engine.routes.routes 

...replacing RailsBlogEngine with the name of your engine, then you can get a rudimentary list of routes by running:

rake routes 

Note that in Rails 3.1.1 and later, you'll need a newer version of the rake routes task.

like image 30
emk Avatar answered Jan 03 '23 11:01

emk