This project is archived and is in readonly mode.

#4400 ✓invalid

[PATCH] Avoid app_const when drawing routes in app generator

Reported by phs | April 15th, 2010 @ 07:02 AM

The app generator's config/routes.rb template draws it routes with <%= app_const %>.routes.draw.

If the application intent is to become an engine, then the app_const (== AppName::Application) would probably need to be changed to at least AppName::Engine.

An alternative that seems to work for both apps and engines is to call Rails.application.routes.draw. Assuming there's no subtle consequences, here (soon) is a patch tweaking the generator to do that.

Comments and changes to this ticket

  • phs
  • Robert Glaser

    Robert Glaser June 9th, 2010 @ 08:40 AM


    There should be at least a "--engine" switch for the "rails xy" generator.

  • José Valim

    José Valim June 22nd, 2010 @ 04:07 PM

    • State changed from “new” to “invalid”

    Engine will have their own routes soon. So you may want it to have its own routes... or not.

  • José Valim

    José Valim June 22nd, 2010 @ 04:07 PM

    Engines will have their own routes soon. So you may want to use Module::Engine.routes.draw... or still manipulate Rails.application directly. That said, it does not really makes sense applying your patch because your assertion won't be necessarily valid soon.

  • phs

    phs June 24th, 2010 @ 08:19 PM

    That's a reasonable stance.

    As a related question, suppose the engine author wants to run her engine as a standalone app (i.e. by using a config/application.rb instead of an Engine subclass) without having to change or have multiple routes.rb files around. One way is to always draw from Rails.application.routes like above, another is to explicitly check for some known types first a la

    (MyHotNewApp::Application rescue MyHotNewApp::Engine).routes.draw { ... }

    Have any preferences for one over the other? I'm totally fine having the engine author (or a support tool) introduce the needed change from the stock routes.rb.

  • José Valim

    José Valim June 24th, 2010 @ 08:28 PM

    Yes, today you will need to resort to hacks in order to have a Rails application working as engine too. But there is a Ruby Summer of Code project to make this easier. :)

  • phs

    phs June 24th, 2010 @ 08:31 PM

    Cool! Incidentally I'd love to be involved in that.

  • José Valim

    José Valim June 24th, 2010 @ 08:35 PM

    I think his project already have primary and secondary mentors, but you can of course follow him on twitter ( and follow his fork (

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=""></a>