12

I'm working with a legacy database and need to create some CRUD's. How can I use the scaffold generator and tell him the exact name of the table avoiding the pluralize process??

Also the tables are in spanish.

mariowise
  • 2,167
  • 2
  • 21
  • 34

2 Answers2

27

You can just use ActiveRecord::Base.table_name= method to manually set the table name.

So, in your model you can do:

class OrderDetail < ActiveRecord::Base
  self.table_name = 'order_detail'
end
MauroPorras
  • 5,079
  • 5
  • 30
  • 41
1andsock
  • 1,557
  • 10
  • 15
  • 3
    I like this one better because when one usually needs that is in a case of an exceptional class name. Your answer is a little bit misleading though. Table name is usually in `lowercase_separated_by_underscores` as found in `Schema.rb`. What you written is used for class names called `UpperCamelCase`. – Ayman Salah Sep 17 '16 at 13:36
24

I think you want

ActiveRecord::Base.pluralize_table_names = false

Found this here:

http://justinram.wordpress.com/2006/04/04/pluralize-table-names-no-thanks/

http://guides.rubyonrails.org/3_1_release_notes.html

Chris Valentine
  • 1,557
  • 1
  • 19
  • 36