Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Avoid app_const when drawing routes in app generator

#4400

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.

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. phs
  2. Robert Glaser
    Robert Glaser

    +1

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

    June 9th, 2010 @ 08:40 AM

  3. José Valim
    José Valim
    • 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.

    June 22nd, 2010 @ 04:07 PM

  4. José Valim
    José Valim

    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.

    June 22nd, 2010 @ 04:07 PM

  5. phs
    phs

    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.

    June 24th, 2010 @ 08:19 PM

  6. José Valim
    José Valim

    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. :)

    June 24th, 2010 @ 08:28 PM

  7. phs
    phs

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

    June 24th, 2010 @ 08:31 PM

  8. José Valim
    José Valim

    I think his project already have primary and secondary mentors, but you can of course follow him on twitter (http://twitter.com/drogus) and follow his fork (github.com/drogus/rails).

    June 24th, 2010 @ 08:35 PM