I’m pretty new to ruby an I try to develop something currently.
But I got an small error when it comes to routing.
my routes.rb
resources :games do
resources :matches
end
game.rb
has_many :matches
match.rb
belongs_to :game
rake routes
new_game_match GET /games/:game_id/matches/new(.:format) matches#new
where error occurs:
<%= link_to 'Add Match', new_game_match_path %>
what error tells:
No route matches [GET] "/games/matches/new"
now i have no idea why he doesn’t route the game_id with it an why it raises this error..
anyone can help me plz?
if it helps, both models and controller were scaffolded but matches controller was edited to fit relations.
The
new_game_match_pathhelper expects agameargument from which to pull thegame_idparameter.Given a game with id
123, stored in a variable called@game, you would invoke it like this:Which would return a path like this:
When you nest routes this way, you’re making a new
matchfor a specificgame, and without including the@gameparameter there is no way to build the URL.You could also use the array syntax. The following is equivalent to
new_game_match_path(@game):