Lesson 7
$rails g scaffold order title:string content:text url:string
rails g model order
rails g controller orders
rails g model post --no-test-framework
rails g controller posts --no-test-framework
rails g model post --no-test-framework
rails g controller posts --no-test-framework
class Group < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :group
end
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.integer :group_id
t.string :title
t.text :content
t.timestamps
end
end
end
class Group < ActiveRecord::Base
has_many :connections
has_many :users, through: :connections
end
class Connection < ActiveRecord::Base
belongs_to :group
belongs_to :user
end
class User < ActiveRecord::Base
has_many :connections
has_many :groups, through: :connections
end
class CreateConnections < ActiveRecord::Migration
def change
create_table :groups do |t|
t.integer :group_id
t.string :title
t.text :content
t.timestamps
end
create_table :connections do |t|
t.integer :group_id
t.integer :user_id
t.timestamps
end
end
end