Search code examples
ruby-on-railsurl-routing

Rails routing shorthand when URL path is the same as method name?


One of the entries in my config/routes.rb:

get "enumerators/job_type", to: "enumerators#job_type"

As you can observe, the URL path and the method name that it corresponds to in the controller is the same. Does Rails provide a shorthand in such cases?


Solution

  • Yep! Rails magic will let you just write: get "enumerators/job_type" in your routes file, as long as your controller name is EnumeratorsController and the method is job_type

    Remember you can always check the routes it's creating by running bundle exec rake routes