Easily namespace your Rails models
If you implement the class method tablenameprefix inside a regular module:
module Invoice
def self.table_name_prefix
'invoice_'
end
end
Then any models you nest inside that module will prepend that prefix onto their table name:
module Invoice
class Customer < ActiveRecord::Base
end
end
Invoice::Customer.table_name # => "invoice_customers"
This is an easy and straightforward way to namespaces models in both your database and application.
Written by S.R.Garcia
Related protips
1 Response
I was wondering how to generate the "namespaced" (at least prefixed) tables though through a Rails migration. This site had this suggestion, which works:
$ rails g model admin/user
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Related Tags
#rails
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#