本文介绍了从污垢访问rails url helper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Spree包含到现有站点中.我正在用Deface更改spree标头,以呈现我网站的标头.因此,我使用以下Deface DSL代码

I am including Spree to an existing site. I am changing the spree header with Deface to render my site's header instead. Therefore I use the following Deface DSL code

<!-- replace_contents "header[data-hook]" -->
<%= render :partial => "layouts/my_site_header.html.erb" %>

_my_site_header.html.erb里面,我有类似的东西

And inside _my_site_header.html.erb I have something like this

<ul>
    <li><%= link_to "Home", home_path %></li>
    <li><%= link_to "Game", game_path %></li>
    <li><%= link_to "Community", community_path %></li>
</ul>

哪个给我以下错误

undefined local variable or method `home_path' for #<#<Class:0x8a73c20>:0x8af0e58>

我知道Deface在Spree范围内执行了代码,因此我的站点的url帮助器是未定义的.我可以使用完整的方法名称(如Rails.application.routes.url_helpers.home_path

I understood that the code get executed by Deface in the Spree scope, thus my site's url helpers are undefined. I could solve this using the full method name like Rails.application.routes.url_helpers.home_path

但是,我真的不希望为我的所有链接添加它.是否没有办法告诉Spree包含我网站的网址帮助程序?请帮忙!

However, I don't really feel like adding this for all of my links. Isn't there a way to tell Spree to include the url helpers of my site? Please help!

推荐答案

您可以在称为Main_app的Rails :: Engine .

<ul>
    <li><%= link_to "Home", main_app.home_path %></li>
    <li><%= link_to "Game", main_app.game_path %></li>
    <li><%= link_to "Community", main_app.community_path %></li>
</ul>

我强烈建议您使用此方法,以避免您的应用程序和Spree之间发生冲突(例如,您的应用程序首页与Spree的首页之间的冲突).

I would highly recommend using this to avoid conflicts between your application and Spree (such as your app home vs. Spree's home).

这篇关于从污垢访问rails url helper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 04:48