看到个 爱奇艺 VIP 用户优先 真是赞
六号主题性挺强的,四号的典雅
屌爆了
注册的时候放弃了。。因为我忘了新浪微博的密码。。。
#18 楼 @blackanger 太棒了,已经准备好金币了
rails 会讲不?
已发,求人品
节操呢
We start by creating a migration:
depot> rails generate migration combine_items_in_cart
This time, Rails can’t infer what we are trying to do, so we can’t rely on the generated change() method. What we need to do instead is to replace this method with separate up() and down() methods.
class CombineItemsInCart < ActiveRecord::Migration
def up
Cart.all.each do |cart|
sums=cart.line_items.group(:product_id).sum(:quantity)
sums.each do |product_id,quantity|
if quantity>1
cart.line_items.where(product_id:product_id).delete_all
item=cart.line_items.build(product_id:product_id)
item.quantity=quantity
item.save!
end
end
end
end
def down
LineItem.where("quantity>1").each do |line_item|
line_item.quantity.times do
LineItem.create cart_id: line_item.cart_id,product_id: line_item.product_id,quantity:1
end
line_item.destroy
end
end
end
新版的 agile web development with rails 4 beta 里面的。
#2 楼 @lidashuang 貌似没人答,洗洗睡吧
我去啊。。我还是意会吧
要翻墙才行啊,本地信息能不能跟你的服务器同步额?
有没有下载地址啊,学生外国网买不了。。