Skip to content

Use isolated engines to simplify namespacing #8

@TylerRick

Description

@TylerRick

Read the "Isolated Engine" section on http://edgeapi.rubyonrails.org/classes/Rails/Engine.html

The next thing that changes in isolated engines is the behaviour of routes. Normally, when you namespace your controllers, you also need to do namespace all your routes. With an isolated engine, the namespace is applied by default, so you can ignore it in routes:
MyEngine::Engine.routes.draw do
  resources :articles
end

The routes above will automatically point to MyEngine::ApplicationContoller. Furthermore, you don’t need to use longer url helpers like my_engine_articles_path. Instead, you should simply use articles_path as you would do with your application.

To make that behaviour consistent with other parts of the framework, an isolated engine also has influence on ActiveModel::Naming. When you use a namespaced model, like MyEngine::Article, it will normally use the prefix “my_engine”. In an isolated engine, the prefix will be omitted in url helpers and form fields for convenience.

polymorphic_url(MyEngine::Article.new) # => "articles_path"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions