Search code examples
hanamihanami-router

Hanami routes helper don't work in templates


I have hanami application version 1.0.0 I have next routes.rb file:

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

I read docs and tried to use

<%= routes.games_path %>

in application.html.erb template, but recieved next error:

Hanami::Routing::InvalidRouteException: No route (path) could be generated for :games - please check given arguments

How can I use routers in hanami templates?


Solution

  • Instead of using resources, you can also add a name to your route:

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

    Read more at: https://guides.hanamirb.org/routing/overview/