【发布时间】:2017-02-11 09:10:42
【问题描述】:
我无法从seed.rb 填充我的数据,当我使用rake db:seed 时没有任何反应。
- 使用 Rails 5。
- 来自 Rails 4 的数据
我可以在 Rails 5 中使用这种结构吗?
Product.delete_all
Product.create!(title: 'CoffeeScript',
description:
%{<p>
CoffeeScript is JavaScript done right. It provides all of JavaScript\'s
functionality wrapped in a cleaner, more succinct syntax. In the first
book on this exciting new language, CoffeeScript guru Trevor Burnham
shows you how to hold onto all the power and flexibility of JavaScript
while writing clearer, cleaner, and safer code.
</p>},
image_url: 'cs.jpg',
price: 36.00)
# . . .
Product.create!(title: 'Programming Ruby 1.9 & 2.0',
description:
%{<p>
Ruby is the fastest growing and most exciting dynamic language
out there. If you need to get working programs delivered fast,
you should add Ruby to your toolbox.
</p>},
image_url: 'ruby.jpg',
price: 49.95)
Product.create!(title: 'Rails Test Prescriptions',
description:
%{<p>
<em>Rails Test Prescriptions</em> is a comprehensive guide to testing
Rails applications, covering Test-Driven Development from both a
theoretical perspective (why to test) and from a practical perspective
(how to test effectively). It covers the core Rails testing tools and
procedures for Rails 2 and Rails 3, and introduces popular add-ons,
including Cucumber, Shoulda, Machinist, Mocha, and Rcov.
</p>},
image_url: 'rtp.jpg',
price: 34.95)
【问题讨论】:
-
播种从 4 到 5 的工作方式没有变化,因此错误一定在其他地方。您尝试向文件添加一些简单的调试,看看它是否正在运行。就像顶部的
puts 'first line',然后应该在控制台中看到。
标签: ruby-on-rails ruby-on-rails-5 seed