Rails Engine Questions

Hi all,

First, I hope everyone has a happy new year and a fun productive
programming year in 2011 with Rails!

I've been working extensively with the Rails::Engine in 3.0.3 and
decided that it was better to move to edge rails since some of the
design, especially routing, was becoming depracated in 3.1.

My 3.0.3 rails engine works fine. My 3.1 engine is still much of a
mystery until I can figure out how some of the endpoints are working.
I've been looking over:


.. and from what I can gather, if you do not set up an endpoint to a
rack application, the default routing under your_engine/config/routes.rb
becomes an endpoint.

Normally in my engine routes I would define the routes by using:

Rails::Application.routes draw do
# routes..

but in the documentation it states that I should be able to do:

MyEngine::Engine.routes.draw do
# routes..

When I require the gem to my new engine using the older way, all of the
engine routes show up fine. When I require the gem to my new engine
using the newer way, zero routes show up. I've tried to read up more on
the way this endpoint is working, but I'm not getting as far as I'd

I could use some help and perhaps even some quality resources/links to
the edge rails way of creating engines, especially where routing is


It appears I can still use:

Rails.application.routes.draw do
# routes

.. but I'd like to ensure that I do things more akin to the way the
engine code is being handled.

Okay I'm making some headway but again, it's not comfortable yet.

I'm able to do the following:

(from the engine app) my_engine/config/routes.rb

MyEngine::Engine.routes.draw do
  resources :test_index, :controller => 'my_engine/test_index'

(from the main app that uses the engine) /config/routes.rb

Testapp::Application.routes.draw do
  mount MyEngine::Engine => '/my_engine', :as => 'my_engine'

And this allows me to use the new engine routes. The only drawback I've
seen so far is that you have to change the way the paths load in the
views. For instance, if I have an index view that has a standard

# my_engine/app/views/my_engine/test_index/index.html.erb
<% @test_indexes.each do |test_index| %>
<%= link_to 'Show', my_engine.test_index_path(test_index) %>
<%= link_to 'Edit', my_engine.edit_test_index_path(test_index) %>
<% end %>

If I don't include the mountable call to my_engine and the path as a
method, I'll receive an undefined method hash_for_ error. So, the above
seems to work fine.

However, if I run rake routes in the new testapp it doesn't show all of
the routes available. It just shows:

my_engine /my_engine (:to=>MyEngine::Engine)

.. so not sure if I like that or how to be able to see all of the
routing paths available from the engine in the new test application.
But, making some progress anyways.

Okay, it took me a few hours but I completed my first engine for rails
3.1 edge. I found several very handy articles and start points in case
anyone else wants to learn more about rails engines. Here are the links
and resources I found:


If anyone has questions, I'd be more than happy to walk you through the
initial stress and labors. But, once you get it going, it feels really


I'd love to see/hear the approach to design and build an engine. How
can I use an engine to share code among like projects? Can I decompose
a larger project into engines? What are the considerations and
pitfalls? Mantras for design?

Hi Martin, go visit this new link I created which will provide a link to
an example rails engine I created. It should help answer all of your