Brand new one here
I've looked and googled and searched.
There are lots of references to RoR Naming Conventions - I haven't
actually been able to locate the list of these conventions.
Is there a single list of conventions?
Or are they defined through out the documentation and you pick them up
as you go?
I'm looking for the Database ones right now.
I've got 8 text files of exported data that I'm putting into a
database and building my first RoR app around this data.
How should this table be done in relation to the RoR conventions?
CREATE TABLE `makes` (
`code` varchar(4) NOT NULL,
`Description` varchar(30) NOT NULL,
PRIMARY KEY (`code`)
Use generic 'id' values as your primary keys.
Keep your column names in typical_ruby_variable_style and certainly not with a capital letter to start since that indicates a constant to Ruby.
CREATE TABLE `years` (
`make_code` varchar(4) NOT NULL,
`family` varchar(7) NOT NULL,
`vehicleType` varchar(2) NOT NULL,
`yearGroup` int(4) NOT NULL,
`monthGroup` int(2) NOT NULL,
`description` varchar(10) NOT NULL,
KEY `make_code` (`make_code`),
KEY `family` (`family`),
KEY `vehicleType` (`vehicleType`),
KEY `yearGroup` (`yearGroup`),
KEY `monthGroup` (`monthGroup`)
Your migration for these tables will have something like:
create_table :makes do |t|
t.column :code, :string, :limit => 4, :null => false
t.column :description, :string, :limit => 30, :null => false
add_index :makes, :code
create_table :years do |t|
t.column :make_code, :string, :limit => 4, :null => false
t.column :family, :string, :limit => 7, :null => false
t.column :vehicle_type, :string, :limit => 2, :null => false
t.column :year_group, :integer, :null => false
t.column :month_group, :integer, :null => false
t.column :description, :string, :limit => 10, :null => false
add_index :years, :make_code
add_index :years, :family
add_index :years, :vehicle_type
add_index :years, :year_group
add_index :years, :month_group
You should then also have validations in your models for the size limits, for example:
validates_length_of :code, :in => 1..4
validates_length_of :description, :in => 1..30
See more at:
You probably also want to avoid names that are "magic" for ActiveRecord like 'type', 'id', 'position', 'updated_at'. I know that you can find a list of these to avoid.
Rob Biedenharn http://agileconsultingllc.com