简体   繁体   English

如何从Rails引擎获取主机路由?

[英]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. 我有一个Rails引擎,该引擎具有将路由,视图,模型和控制器插入主机应用程序中。

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? 如何提供从主机到引擎的路由?

You need to use 您需要使用

main_app.route_from_my_host_application

This way engine will find for the path in your host routes 这样引擎将在您的主机路由中查找路径

Take a look at the answer in How can I make routes from a Rails 3 engine available to the host application? 查看如何使来自Rails 3引擎的路由可供主机应用程序使用的答案

Change config.routes in your engine to: 将引擎中的config.routes更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM