-1

I have created a new rails 4 Engine and try to work no mount routes for the newly created Engine but it did not worked for me below are the files.

app/routes.rb (root routes file)

Rails.application.routes.draw do
  mount Uhoh::Engine => "/uhoh"
  resources :products
end

new_engine/config/routes.rb (Engine routes file)

Uhoh::Engine.routes.draw do
  get "failures#index"
end

uhoh/lib/uhoh/engine.rb (engine file)

module Uhoh
  class Engine < ::Rails::Engine
    isolate_namespace Uhoh
  end
end

but when I have run "rake routes" command from treminal then it does not show the routes from the "Uhoh" engine.

Prefix Verb   URI Pattern                  Controller#Action
        uhoh        /uhoh                        Uhoh::Engine
    products GET    /products(.:format)          products#index
             POST   /products(.:format)          products#create
 new_product GET    /products/new(.:format)      products#new
edit_product GET    /products/:id/edit(.:format) products#edit
     product GET    /products/:id(.:format)      products#show
             PATCH  /products/:id(.:format)      products#update
             PUT    /products/:id(.:format)      products#update
             DELETE /products/:id(.:format)      products#destroy

Routes for Uhoh::Engine:
user229044
  • 232,980
  • 40
  • 330
  • 338
user3906755
  • 103
  • 3
  • 11

1 Answers1

2

$ rails plugin new blorgh --mountable An app directory tree A config/routes.rb file: A file at lib/blorgh/engine.rb, which is identical in function to a standard Rails application's config/application.rb file: module Blorgh class Engine < ::Rails::Engine end end

The --mountable option will add to the --full option:

Asset manifest files (application.js and application.css) A namespaced ApplicationController stub A namespaced ApplicationHelper stub A layout view template for the engine Namespace isolation to config/routes.rb:

Blorgh::Engine.routes.draw do end

Namespace isolation to lib/blorgh/engine.rb:

module Blorgh class Engine < ::Rails::Engine isolate_namespace Blorgh end end

Additionally, the --mountable option tells the generator to mount the engine inside the dummy testing application located at test/dummy by adding the following to the dummy application's routes file at test/dummy/config/routes.rb:

mount Blorgh::Engine => "/blorgh"

app/controllers/blorgh/articles_controller.rb:

require_dependency "blorgh/application_controller"

module Blorgh class ArticlesController < ApplicationController ... end end

Sachin
  • 353
  • 1
  • 10