2

I am working on Rails 4.1.0. And i have generated leaves_controller and Leave model in my application.

But the application generated routes for leaves as like new_leafe, edit_leaf etc.

Actually I want the singularize string of Leave as Leave only, like new_leave_path, edit_leave_path.

If any idea to singularize class name in Rails, please share.

Prachi Dhabu
  • 113
  • 6

1 Answers1

5

If it's only the routes you wish to change, you could use the as: option:

#config/routes.rb
resources :leaves, as: "leave"

--

Alternatively, if you'd like to set the term within Rails, you may wish to use an Inflector like this:

How do I override rails naming conventions?

#config/initializers/inflectors.rb
# Add new inflection rules using the following format 
ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'leave', 'leaves'
end
Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147