【问题标题】:Hanami routes helper don't work in templatesHanami 路线助手在模板中不起作用
【发布时间】:2017-09-14 19:43:52
【问题描述】:

我有 hanami 应用程序版本 1.0.0 我有下一个 routes.rb 文件:

get '/games', to: 'games#index'
root to: 'home#index'

我阅读了docs 并尝试使用

<%= routes.games_path %>

在 application.html.erb 模板中,但收到下一个错误:

Hanami::Routing::InvalidRouteException: 无法为 :games 生成路由(路径) - 请检查给定的参数

如何在 hanami 模板中使用路由器?

【问题讨论】:

    标签: hanami hanami-router


    【解决方案1】:

    除了使用resources,您还可以为您的路线添加一个名称:

    get '/games', to: 'games#index', as: :games
    

    阅读更多:https://guides.hanamirb.org/routing/overview/

    【讨论】:

      【解决方案2】:

      我加了

      resources :games, only: [:index]
      

      到我的 routes.rb 文件,这解决了我的问题。

      【讨论】:

        猜你喜欢
        • 2016-05-04
        • 2013-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多