Rich
Rich

Reputation: 5731

How to get host routes from a rails engine?

I have a rails engine that has routes, views, models and controllers plugged into the host application.

I mount the engine in host routes like so:

mount HelpCenter::Engine, at: "/help_center"

When I go to a view provided by the engine (it is using a layout from the host), it is getting errors when it tries to resolve routes from the navigation bar (host routes).

How do I provide routes from the host into the engine?

Upvotes: 0

Views: 896

Answers (2)

Deepak Mahakale
Deepak Mahakale

Reputation: 23671

You need to use

main_app.route_from_my_host_application

This way engine will find for the path in your host routes

Upvotes: 3

kcdragon
kcdragon

Reputation: 1733

Take a look at the answer in How can I make routes from a Rails 3 engine available to the host application?

Change config.routes in your engine to:

Rails.application.routes.draw do  # NOT MyEngineName::Engine.routes.draw
  resources :classrooms
end

Upvotes: 0

Related Questions