skip to Main Content

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


  1. use a new rails syntax rather than using old syntax

    get 'to-do', to: 'current_to_do_items#landing', as: 'to-do'
    
    Login or Signup to reply.
  2. :as option generates urls helpers, even if you change it to as: "to-do" your helpers will not change: to_do_path and to_do_url. All of these generate the same route and helpers:

    # technically, you don't need :as option here, because it's the same as path
    get "to-do", to: "current_to_do_items#landing"
    
    get "to-do", to: "current_to_do_items#landing", as: :to_do
    get "to-do", to: "current_to_do_items#landing", as: "to-do"
    

    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:

    { "to-do": :"to do!" }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search