How do I explicitly specify a Model's table-name mapping in Rails?
Ruby on-RailsRuby on-Rails Problem Overview
I have a Model class called Countries and I want it to map to a DB table called 'cc'.
How is that done in Rails?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
Rails >= 3.2 (including Rails 4+ and 5+):
class Countries < ActiveRecord::Base
self.table_name = "cc"
end
Rails <= 3.1:
class Countries < ActiveRecord::Base
self.set_table_name "cc"
...
end
Solution 2 - Ruby on-Rails
class Countries < ActiveRecord::Base
self.table_name = "cc"
end
In Rails 3.x this is the way to specify the table name.