Cart.create 我们一般CRUD create action 中为什么不用.create 而用.new?
Closed this issue · 1 comments
DJ-MinorG commented
def find_cart
cart = Cart.find_by(id: session[:cart_id])
if cart.blank?
cart = Cart.create
end
session[:cart_id] = cart.id
return cart
end
kurotyan514 commented
create 等於 new + save
你要用new也可以,就是要記得save