Prior to this PR, we would have to build paths to records manually, e.g. depot/games/#{game.slug}. However, this is not ideal, as Rails has a convention that implicitly generates paths.
Solution
Add a #to_param method to User and Game that overrides the expected param to be used in the path. Now paths can properly be automatically generated with the path helpers (user_path, url_for, etc.)
⚠️ Note!
This will mean that paths for games will no longer be routed through the /depot/games path, and instead will be routed simply in /games. I'm sure there is a way to change this without breaking the auto-generated paths (I like these being under /depot), but I'll leave that for later. 🙂
Problem
Prior to this PR, we would have to build paths to records manually, e.g.
depot/games/#{game.slug}
. However, this is not ideal, as Rails has a convention that implicitly generates paths.Solution
Add a
#to_param
method toUser
andGame
that overrides the expected param to be used in the path. Now paths can properly be automatically generated with the path helpers (user_path
,url_for
, etc.)⚠️ Note!
This will mean that paths for games will no longer be routed through the
/depot/games
path, and instead will be routed simply in/games
. I'm sure there is a way to change this without breaking the auto-generated paths (I like these being under/depot
), but I'll leave that for later. 🙂