Feature Request: config option to prefer "dashed" routes over "underscored"

Everyone agrees that hyphenated urls are better for SEO; Google themselves say you should prefer hyphens to underscores.

Hyphens are easier to type than underscores for the average user, less likely to be missed when reading, and again better for SEO in URLs

Rails generated routes should at least have the option to use hyphens in path output without needing to do resources "something-with-multiple-words", as: :something_with_multiple_words

To not break backwards compatibility, I was thinking a config flag for the application.rb file like: Rails.application.config.use_dashed_routes = true

With this flag, resources :something_with_multiple_words would still point to the same controller and create the same path/url helpers, but the outputted path and route would generate and respond to /something-with-multiple-words instead of /something_with_multiple_words

2 Likes

I’ve set up a web service to translate your routes.rb files from one to the other format for everyone. You can hit the endpoint using the following shell command: curl -s -L -X POST ‘https://units.d8u.us/underscores2dashes’ -H ‘Content-Type: application/json’ --data-raw ‘{ “inComing”: “__yes_WECan”}’ and it will yield { “incoming”: “__yes_WECan”, “translated”: “–yes-WECan” }

Send your hairiest of routes files, and let me know if you hit some bugs? Thanks – H

I appreciate the effort, but I highly doubt your service rewrites things in a cleaner way than I already have my routes set up. Your service to rewrite routes files has nothing to do with the the need to have this as a native option for resources

1 Like