如何在Rails应用程序中识别路线 [英] How to recongnise routes in a Rails App

查看:91
本文介绍了如何在Rails应用程序中识别路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题。我正在使用仪表板导轨引擎,这给了我视图/layouts/dashing/dashboard.html.erb 。这是仪表板视图的布局。

I have this very basic question. I am using this dashboard rails engine, and this gives me a views/layouts/dashing/dashboard.html.erb. This is the layout of the dashboard view.

但是我想自定义此视图,例如添加导航栏,该视图的链接指向我的 about_path 。但是,在仪表板视图中未识别任何路由。这会导致错误未定义的方法about_path

But I want to customize this view, like add a navigation bar, that has a link which point to my about_path. However, none of the routes are recognized in the dashboard view. It results in an error undefined method about_path.

但是 about_path 路由是在我的路由文件中定义的,并且在其他不属于仪表板的视图中运行良好

But the about_path route is defined in my routes file and is working fine in other views that dont belong to dashboard.

Rails引擎可以识别我的应用程序中定义的路由吗?

Is there any way a rails engine recognizes routes defined in my application?

推荐答案

如果您希望以类似的方式引用引擎内部的应用程序,请使用main_app帮助器:

If you wish to reference the application inside the engine in a similar way, use the main_app helper:

<%= link_to "About", main_app.about_path %>

此处是参考链接铁路路线指南

这篇关于如何在Rails应用程序中识别路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆