Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2012 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3420711 to your computer and use it in GitHub Desktop.
Save anonymous/3420711 to your computer and use it in GitHub Desktop.
Basic ruby blog model set up
class Comment < ActiveRecord::Base
attr_accessible :content, :score
has_one :user
belongs_to :post
end
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.text :content
t.integer :score
t.timestamps
end
end
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :content
t.integer :score
t.timestamps
end
end
end
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.integer :score
t.timestamps
end
end
end
class Post < ActiveRecord::Base
attr_accessible :title, :content, :score
has_one :user
has_many :comments
end
ActiveRecord::Schema.define(:version => 20120821235424) do
create_table "comments", :force => true do |t|
t.text "content"
t.integer "score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "posts", :force => true do |t|
t.string "title"
t.text "content"
t.integer "score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.string "password"
t.integer "score"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
class User < ActiveRecord::Base
attr_accessible :name, :email :password, :score
has_many :posts
has_many :comments
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment