Rails - Model name ends with S

Viewed 5899

I have a model named ActiveDns. When I run

rails g scaffold_controller ActiveDns

I get the message

Plural version of the model detected, using singularized version. Override with --force-plural.

Now, the controller and views are generated pretending that the singular is ActiveDn and the plural is ActiveDns, and I get silly stuff like link_to new_dn_path. The --force-plural argument doesn't appear to fix this:

rails g scaffold_controller ActiveDns --force-plural

still results in controllers using variables named @active_dn and views using new_dn_path, with rails 3.2.3. I am removing files between tries using rails d scaffold_controller ActiveDns.

What's the right way to do this?

3 Answers

I want to share about how I solve my problem.

I have an MVC with a name of Pacman under Data_Warehouse.

Where Pacman is a proper noun. (Cannot be Pacmen with an e, but should be Pacmans with an s)

And Data_Warehouse is like a platform name. (Could be anything, in this case its DataWarehouse::Pacman)

So, I have

Models name - models/data_warehouse/pacman.rb

Views name - views/data_warehouse/pacmans/index.slim

Controller name - controller/data_warehouse/pacmans_controller.rb

The problem is, Rails read this path

data_warehouse_pacmans_path

as

data_warehouse_pacmen_path

because of pluralization.

So

I solved this by adding

ActiveSupport::Inflector.inflections do |inflect|
   inflect.uncountable %w( pacmans )
end

to the inflections.rb file in Rails.

Hope this would helps

Related