Forum: Ruby on Rails Table prefix

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Davide B. (Guest)
on 2006-01-11 21:28
(Received via mailing list)
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??


Jan P. (Guest)
on 2006-01-11 22:14
(Received via mailing list)
Hi, Davide,

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

Best regards
Jan P.
Nick S. (Guest)
on 2006-01-12 02:11
(Received via mailing list)
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 topic is locked and can not be replied to.