Reputation: 419
Since the command rails g model ModelName generates a migration for creating the table, I want to make the name of the table look right. The name of my model is CategoryProduct and its pluralized version should be CategoriesProduct. The model name comes right. But when I run the command to generate the model the migrations comes like this:
class CreateCategoryProducts < ActiveRecord::Migration[5.0]
def change
create_table :category_products do |t|
t.timestamps
end
end
end
I already changed the file initializers/inflections.rb to made the correction:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'categoryproduct', 'categoriesproduct'
end
So, why is it still generating the wrong name with underscore?
Upvotes: 2
Views: 654
Reputation: 171
If you want your tablename to be categoriesproduct, then create a table with the desired name and specify the tablename in the model.
class CategoryProduct < ActiveRecord::Base
self.table_name = "categoriesproduct"
end
Upvotes: 2