quanzhanying/fullstack-course

Cart.create 我们一般CRUD create action 中为什么不用.create 而用.new?

Closed this issue · 1 comments

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

create 等於 new + save
你要用new也可以,就是要記得save