Permalink
Browse files

Seed with 1 post and 3 comments

  • Loading branch information...
1 parent 7d9b0a4 commit 5c3beb16c618558132fa7d0ef252d441d3c0bb3a @prathe committed Feb 17, 2012
Showing with 12 additions and 1 deletion.
  1. +7 −1 README.md
  2. +5 −0 db/seeds.rb
View
8 README.md
@@ -2,16 +2,22 @@
**Rails 3.2.1**
+## Setup
+
rails new accepts_nested_attributes_for-demo
cd accepts_nested_attributes_for-demo
bundle exec rails g scaffold Post title:string content:text
bundle exec rails generate model Comment content:text post:references
bundle exec rake db:create db:migrate
-*app/models/post.rb*
+Edit *app/models/post.rb*
+
class Post < ActiveRecord::Base
has_many :comments, :dependent => :destroy
accepts_nested_attributes_for :comments, allow_destroy: true
end
+### Continue setup…
+
+ bundle exec rake db:seed
View
5 db/seeds.rb
@@ -5,3 +5,8 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+post = Post.create! title: 'First post', content: "Playing with accepts_nested_attributes_for"
+post.comments << Comment.create!(content: "Update me please!")
+post.comments << Comment.create!(content: "Yeah, me too please!")
+post.comments << Comment.create!(content: "If you don't mind, I'd like to also.")

0 comments on commit 5c3beb1

Please sign in to comment.