Table prefix

Hi everybody,
is it possible to override standard RoR table nomination/pluralization
to include a suffix? I have some tables with usr_ prefix but i would use
“real” table name in model naming. For example i have table
usr_accesslogs; in normal use i should create a model called
UsrAccesslog instead Accesslog.
Is it possible to do this??



Hi, Davide,

have a look at ActiveRecord::Base#set_table_name
( and

Best regards
Jan P.

Another way to get prefixes for all your class is to do something like
the following.
Make a new folder in plugins called prefixed (or whatever)
Add a file init.rb with require ‘prefixed’ in it…
Add a directory ‘lib’ with a sinlge file ‘prefixed.rb’ in it.
Then in prefixed.rb add the following:

module ActiveRecord
class Base
class << Base
alias :original_table_name :table_name
def table_name
#could setup a lot more complicated rules here.

that way everything will work as it used to, but also add the prefix
to all your models for free. I’m not sure what you could do with the
rules to get the prefix value, but something more interesting then
what I have there should be doable.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs