2

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

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

我阅读了文档并尝试使用

<%= routes.games_path %>

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

Hanami::Routing::InvalidRouteException: No route (path) could be generated for :games - 请检查给定的参数

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

4

2 回答 2

5

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

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

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

于 2017-04-19T19:26:57.040 回答
1

我添加了

resources :games, only: [:index]

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

于 2017-04-19T12:57:13.067 回答