This question is fairly old but I stumbled across it looking for a way to handle the word staff(as in employees at a company) correctly.
The reason it pluralises with the 's' is because the plural of staff(as in wizards staff) is staffs(staves is also valid). So if you needed a table with different kinds of (wizards)staffs it is valid. However the plural of staff(as in people at a company) is staff.
Rails assumes that you are referring to the wizards staff in this instance. With words with only one meaning that don't have a separate plural, this works correctly:
[1] pry(main)> "sheep".pluralize == "sheep"
=> true
How to fix this?
config/initializers/inflections.rb
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural "staff", "staff"
end
This will tell rails that the plural of staff is staff and the naming conventions will be respected.
rails generate scaffold staff name:string description:text active:boolean
invoke active_record
create db/migrate/20220518125452_create_staff.rb
create app/models/staff.rb
invoke test_unit
create test/unit/staff_test.rb
create test/fixtures/staff.yml
invoke resource_route
route resources :staff
invoke inherited_resources_controller
create app/controllers/staff_controller.rb
invoke erb
create app/views/staff
create app/views/staff/index.html.erb
create app/views/staff/edit.html.erb
create app/views/staff/show.html.erb
create app/views/staff/new.html.erb
create app/views/staff/_form.html.erb
invoke test_unit
create test/functional/staff_controller_test.rb
invoke helper
create app/helpers/staff_helper.rb
invoke test_unit
create test/unit/helpers/staff_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/staff.js.coffee
invoke scss
create app/assets/stylesheets/staff.css.scss
invoke scss
identical app/assets/stylesheets/scaffolds.css.scss
The migration:
create_table :staff do |t|
t.string :name
t.text :description
t.boolean :active
t.timestamps
end
Edit:
ActiveSupport also has uncountable
.
Thats means to handle things like sheep and fish.
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable %w( staff )
end