播种具有has_many关系的rails应用程序

时间:2015-07-23 00:09:21

标签: ruby-on-rails seeding

尝试在过去的5个小时内创建一个种子((...如果您有任何想法请帮忙,因为我是Rails的新手,我的种子似乎非常错误......您可以在这里查看我的所有文件:

我的user.rb:

EditorTemplate

我的食谱.rb:

<input type="text" name="[0].trackingnumber" ... />
<input type="text" name="[1].trackingnumber" ... />
<input type="text" name="[3].trackingnumber" ... />

my ingredient.rb:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  has_many :recipes
end

我的指示.rb:

class Recipe < ActiveRecord::Base
  belongs_to :user

  has_many :ingredients
  has_many :directions

  accepts_nested_attributes_for :ingredients,
                              reject_if: proc { |attributes| attributes['name'].blank? },
                              allow_destroy: true
  accepts_nested_attributes_for :directions,
                              reject_if: proc { |attributes| attributes['step'].blank? },
                              allow_destroy: true

  validates :title, :description, :image, presence: true
  has_attached_file :image, styles: { :medium => "400x400#" }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/

end

我的schema.rb:

class Ingredient < ActiveRecord::Base
  belongs_to :recipe
end

我试着创建一个seeds.rb:

class Direction < ActiveRecord::Base
  belongs_to :recipe
end

0 个答案:

没有答案