Why there is no syntax to explicitly link_to route? (I am new to Rails)
I’ve got this defined route.
get "/donate", to: "contributions#donate"
Linking to it with explicit /donate
param will break URL if route changes and the users will get 404 errors.
= link_to "Donate reglarly", "/donate"
I found no way to validate that all link_to
URLs exist before deployment, and I doubt that with /donate
it is possible, because it is just raw “href” value that doesn’t know anything about routes of controllers.
What I expected is a way to explicitly link to route to get an error if there is a link_to
that refers to missing route. I thought that something like this should be possible.
= link_to "Donate reglarly", route: "/donate"
There is a possibility to use as: donate
in route and then donate_url
in link code, but that’s not intuitive and requires non-trivial rules to grep the code for all links to /donate
.