我正在关注制作购物车的教程,我对这个命令lib/dev.rake
感到困惑。
在此命令之后,它告诉我将此代码放在namespace :dev do
desc "Generate fake data"
task fakeup: ['db:schema:load', :environment] do
20.times do |i|
Product.create(
name: "product no.#{i}", description: "description no.#{i}",
price: (rand(10) + 1) * 50, stock: rand(91) + 10
)
end
cart = Cart.create
Product.all.sample(5).each do |product|
cart.line_items.create product: product, unit_price: product.price, quantity: rand(4) + 1
end
end
end
有人可以解释一下吗?请。
type_of(t[i]) == type_of(t[j])