Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force the singular table name on Rails scaffold generator?

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.

like image 889
mariowise Avatar asked Jul 12 '14 22:07

mariowise


2 Answers

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

like image 159
Chris Valentine Avatar answered Nov 04 '22 23:11

Chris Valentine


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
like image 25
1andsock Avatar answered Nov 05 '22 00:11

1andsock