Skip to content

Instantly share code, notes, and snippets.

@cjcjameson
Created May 29, 2014 21:43
Show Gist options
  • Save cjcjameson/15324cfd5034de2cd8f9 to your computer and use it in GitHub Desktop.
Save cjcjameson/15324cfd5034de2cd8f9 to your computer and use it in GitHub Desktop.
ActiveRecord Filenames that Have to be the same (cheatsheet)
*_Migration file:_*
- Filename (snake_case) ~= class name (CamelCase), which inherits < ActiveRecord::Migration
- create_table :names (as a symbol and pluralized) stands for the table name, and its singular version is used in the model and class definitions (see below!)
EXAMPLE: Filename is 20140529101030_create_database.rb
class CreateDatabase < ActiveRecord::Migration
def change
create_table :tasks do |t|
t.text :description #name
t.boolean :completed_flag
t.timestamps
end
end
end
*_Model file:_*
- Should be named after the table title, but singular (task.rb, menu_item.rb) [This seems to be because of the autoload structure defined in the application.rb file, but we're not sure.]
- The class built within the file should be the same name, singular and CamelCase
class Task < ActiveRecord::Base
class MenuItem < ActiveRecord::Base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment