I need to change underscores to hyphens for SEO of our to-do checklist page in Ruby on Rails project. The relevant line in routes.rb file is below:
get 'to_do' => 'current_to_do_items#landing', :as => :to_do
I tried to change it to:
get 'to-do' => 'current_to_do_items#landing', :as => :to-do
but in this part "as => :to-do" do is detected as a key word,
could you please advise how should I name it?
2
Answers
use a new rails syntax rather than using old syntax
:as
option generates urls helpers, even if you change it toas: "to-do"
your helpers will not change:to_do_path
andto_do_url
. All of these generate the same route and helpers:https://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Base.html#method-i-match
You can quote symbols if you have characters other than letters and underscores: