错误
rake aborted!IngredIEnt(#xxxxxxx) expected,got Hash(#xxxxxxx)Tasks: top => db:seed(See full trace by running task with --trace)
食谱
class Recipe < ActiveRecord::Base attr_accessible :Title,:descrition,:image has_many :ingredIEnts accepts_nested_attributes_for :ingredIEntsend
成分
class IngredIEnt < ActiveRecord::Base attr_accessible :measure,:modifIEr,:item,:note belongs_to :recipeend
Seed.rb(这里的例子有2种成分,每种成分的每一行都有含量)
Recipe.create([{ Title: "Recipe Title here",description: "This is the description",image: "theimage.jpg",ingredIEnts_attributes: [{measure: "1cup",modifIEr: "canned",item: "Mushrooms",note: "drained"},{measure: "1lb",modifIEr: "sliced",item: "Bacon",note: "prevIoUsly cooked"},]}],without_protection: true)解决方法 你可以这样做:
recipe = Recipe.create({ Title: "Recipe Title here",image: "theimage.jpg"})recipe.ingredIEnts.create(measure: "1cup",note: "drained")recipe.ingredIEnts.create(measure: "1lb",note: "prevIoUsly cooked"})总结
以上是内存溢出为你收集整理的ruby-on-rails – 以has_many关系播种全部内容,希望文章能够帮你解决ruby-on-rails – 以has_many关系播种所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)