After including rails engine layout in application gives routing error?

154 Views Asked by At

I am using Rails 5.2.3 and ruby 2.4.0p0

I already have an rails application, now I have created a new Rails engine with some functionality I have included it in the main application as:

In gemfile:

gem 'myengin', path: '/home/vidur/rails_apps/myengin'

For routing:

 mount Myengin::Engine => "/myengin", as: "myengin"   

I want to show the pages in the mounted engine inside the layout of the main application so for doing it I have extended the application controller of the main application in the application controller of the mounted engine as:

module Myengin
   class ApplicationController < ::ApplicationController
    protect_from_forgery with: :exception
  end
end

After doing it it will render the layout of the main application but it will give the routing errors, It will not detect the routing of the main application on these pages and show routing undefined error, But they exists in the routes.rb in the main application. Example:

undefined local variable or method `tukabank_cart_path' for #<#<Class:0x00000004e353b0>:0x00000004e237f0> 

defined in main application routed.rb as:

 resource :tukabank_cart, only: [:show]

Similarly for other routes, all the variables defined as _path give trigger the undefined error But they are defined.

Why is the routing not getting detected on the mounted engine pages? Is there a way around, or should I keep the layout of the main application free from _path variable of the main application?

0

There are 0 best solutions below