Ruby on rails 种子设定rails应用程序与有许多关系
在过去5小时内尝试创建种子((…如果您有任何想法,请帮助,因为我是Rails新手,我的种子似乎非常错误…您可以在此处查看我的所有文件: my user.rb:Ruby on rails 种子设定rails应用程序与有许多关系,ruby-on-rails,seeding,Ruby On Rails,Seeding,在过去5小时内尝试创建种子((…如果您有任何想法,请帮助,因为我是Rails新手,我的种子似乎非常错误…您可以在此处查看我的所有文件: my user.rb: class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :recipes end
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :recipes
end
我尝试创建一个seeds.rb:
r1 = Recipe.create(
title: "Red, White and Blue Poke Cake",
description: "Red, white and beautiful! A simple cake-mix cake becomes the hit of your Fourth of July gathering with just a few easy additions.",
image: "http://s3.amazonaws.com/gmi-digital-library/665dd965-1b01-46ea-8f32-4b745b037817.jpg",
user_id: "1",
image_file_name: "name",
image_content_type: "/\Aimage\/.*\Z/",
image_file_size: "400x400#",
)
r1.ingredients.create(name: "1
box Betty Crocker™ SuperMoist™ white cake mix
Water, vegetable oil and egg whites called for on cake mix box
1
box (4-serving size) strawberry-flavored gelatin
1 cup milk", recipe_id: r1.id )
r1.directions.create(step: "1 Heat oven to 350°F (325°F for dark or nonstick pan). Make and bake cake mix as directed on box for 13x9-inch pan. Cool completely in pan, about 1 hour.
2 Pierce cooled cake with fork at 1/2-inch intervals. In medium bowl, stir gelatin and boiling water until dissolved. Stir in cold water. Carefully pour mixture over entire surface of cake. Refrigerate at least 3 hours until serving time.
3 In large bowl, mix pudding mix and milk until well blended. Gently stir in whipped topping. Spread over cake. Arrange strawberries and blueberries on top of cake to look like flag. Store loosely covered in refrigerator.",
recipe_id: r1.id )
你在发帖时遇到了什么错误?
class Ingredient < ActiveRecord::Base
belongs_to :recipe
end
class Direction < ActiveRecord::Base
belongs_to :recipe
end
ActiveRecord::Schema.define(version: 20150721133516) do
create_table "directions", force: :cascade do |t|
t.text "step"
t.integer "recipe_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "directions", ["recipe_id"], name: "index_directions_on_recipe_id"
create_table "ingredients", force: :cascade do |t|
t.string "name"
t.integer "recipe_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "ingredients", ["recipe_id"], name: "index_ingredients_on_recipe_id"
create_table "recipes", force: :cascade do |t|
t.string "title"
t.text "description"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
r1 = Recipe.create(
title: "Red, White and Blue Poke Cake",
description: "Red, white and beautiful! A simple cake-mix cake becomes the hit of your Fourth of July gathering with just a few easy additions.",
image: "http://s3.amazonaws.com/gmi-digital-library/665dd965-1b01-46ea-8f32-4b745b037817.jpg",
user_id: "1",
image_file_name: "name",
image_content_type: "/\Aimage\/.*\Z/",
image_file_size: "400x400#",
)
r1.ingredients.create(name: "1
box Betty Crocker™ SuperMoist™ white cake mix
Water, vegetable oil and egg whites called for on cake mix box
1
box (4-serving size) strawberry-flavored gelatin
1 cup milk", recipe_id: r1.id )
r1.directions.create(step: "1 Heat oven to 350°F (325°F for dark or nonstick pan). Make and bake cake mix as directed on box for 13x9-inch pan. Cool completely in pan, about 1 hour.
2 Pierce cooled cake with fork at 1/2-inch intervals. In medium bowl, stir gelatin and boiling water until dissolved. Stir in cold water. Carefully pour mixture over entire surface of cake. Refrigerate at least 3 hours until serving time.
3 In large bowl, mix pudding mix and milk until well blended. Gently stir in whipped topping. Spread over cake. Arrange strawberries and blueberries on top of cake to look like flag. Store loosely covered in refrigerator.",
recipe_id: r1.id )