[SOLVED] Hanami routes helper don't work in templates


#1

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?


#2

The helpers work with the resource routes only, as they create named routes


#3

Thank you, I added
resources :games, only: [:index]
to my routes.rb file and this fixed my problem


#4

@milovidov For the record, it worked because resources adds names to the routes automatically.

Just wanted to point out to have a complete picture of how routing helpers work. :wink: