[英]How to access root_path with url param (in host app, from rails engine)?
engine's routes.rb
: 引擎的
routes.rb
:
MyEngine::Engine.routes.draw do
get '/:guid', :to => 'foo_bar#index'
end
mounted in host app via mount MyEngine::Engine, :at => '/some_route'
通过
mount MyEngine::Engine, :at => '/some_route'
安装在主机应用程序中
Somewhere in a helper in the host app: 主机应用程序中某个助手中的某个位置:
generated_link = my_engine.root_path(some_guid_i_got)
results in 结果是
undefined method `root_path' for #<ActionDispatch::Routing::RoutesProxy:0x00007ff443d405a0>
I tried adding include MyEngine::Engine.routes.url_helpers
, but that broke a bunch of other routes that aren't even related to the engine. 我尝试添加
include MyEngine::Engine.routes.url_helpers
,但这破坏了许多其他甚至与引擎无关的路由。 Engine is working other than this url-helper, but I don't want to hard-code the url in. 引擎正在工作,而不是此url-helper,但我不想在其中硬编码URL。
What's the proper way of generating the url for /some_route/a-guid-here
? 为
/some_route/a-guid-here
生成url的正确方法是什么?
Thanks in advance 提前致谢
The error is letting you know what's wrong. 错误是让您知道出了什么问题。
undefined method root_path
is letting you know that it can't find the root_path
defined and that is a required path to have in your routes file. undefined method root_path
让您知道它找不到已定义的root_path
,这是您的路由文件中必须具有的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.