【问题标题】:Rails Forem Engine routes not workingRails Forem Engine 路线不起作用
【发布时间】:2013-08-21 19:32:25
【问题描述】:

我正在尝试在我的 rails 应用程序中安装 Forem。我将它添加到我的 Gemfile 并正确安装。但是,每当我尝试在 Forem 的控制下加载页面(例如“/forums”)时,我都会在非 Forem 路由的链接上获得 NoMethodError's。这些链接位于我的application.html.erb 中包含的部分标题中,称为_header.html.erb

<div id="nav">
    <div id="nav-wrapper">
    <%= link_to raw("<div>Home</div>"), :root %>
    <%= link_to raw("<div>Forums</div>"), :forem %>
    <%= link_to raw("<div>Events</div>"), :events %>
    <%= link_to raw("<div>Applications <b class='carat'>▼</b></div>"), "#"%> 
    <%= link_to raw("<div>Reports <b class='carat'>▼</b></div>"), "#"%> 
    <%= link_to raw("<div>Tutorials</div>"), "#"%>
    <%= link_to raw("<div>Rules</div>"), '#'%>
    <%= link_to raw("<div>Roster</div>"), :roster %>
    <%= link_to raw("<div>Donations</div>"), '#'%>
    <%= link_to raw("<div>Media Center <b class='carat'>▼</b></div>"), '#'%> 
    <%= link_to raw("<div>L.O.A</div>"), '#'%>
</div>

routes.rb:

mount Forem::Engine, :at => '/forums'  
resources :events
resources :news
devise_for :users
get 'roster' => "users#roster"
get 'news' => "news#index"
get 'profile/:user' => "users#profile", :as => :user_path
root 'news#index'

错误:

Forem::Forums#index 中的 NoMethodError

# 的未定义方法“forem_path”>

对于所有其他链接,依此类推:

Forem::Forums#index 中的 NoMethodError

# 的未定义方法“events_path”>

Forem::Forums#index 中的 NoMethodError

# 的未定义方法“roster_path”>

这与routes.rb 的作用域有关,但我不确定如何才能使这些链接再次工作。

【问题讨论】:

    标签: ruby-on-rails ruby routes ruby-on-rails-4


    【解决方案1】:

    我没有使用过 Forem,但 Monologue 也遇到了同样的问题。我认为,如果您的标题中的链接指定它们是 main_app 的一部分,这将有所帮助。示例:

    根路径的原始链接可能是:

    root_path
    

    现在应该是:

    main_app.root_path
    

    原因是 Forem Rails 引擎是一个单独的 Rails 应用程序,没有前缀的链接只能在当前的 Rails 应用程序(在本例中为主应用程序)中工作。

    【讨论】:

    • 请注意,我不确定使用 :root 代替 root_path 的语法应该是什么样子。但是,如果您将其更改为 root_path(其余路径以此类推),然后将 main_app.在每个人面前。
    猜你喜欢
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 2012-07-07
    相关资源
    最近更新 更多