public
anonymous / comment.rb
Created

Basic ruby blog model set up

  • Download Gist
comment.rb
Ruby
1 2 3 4 5 6
class Comment < ActiveRecord::Base
attr_accessible :content, :score
has_one :user
belongs_to :post
end
create_comments.rb
Ruby
1 2 3 4 5 6 7 8 9 10
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
 
t.text :content
t.integer :score
t.timestamps
end
end
end
create_posts.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
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
create_users.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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
post.rb
Ruby
1 2 3 4 5 6
class Post < ActiveRecord::Base
attr_accessible :title, :content, :score
has_one :user
has_many :comments
end
schema.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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
user.rb
Ruby
1 2 3 4 5 6 7 8
class User < ActiveRecord::Base
attr_accessible :name, :email :password, :score
has_many :posts
has_many :comments
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.