商品未添加到购物车

时间:2018-08-11 08:27:03

标签: ruby-on-rails

单击“添加”按钮,所选项目未添加到购物车 参数正确传递,请检查并帮助

Mysql2::Error: Unknown column 'items.cart_id'
in 'where clause': SELECT `items`.* FROM `items`
WHERE `items`.`disable` = 0 AND `items`.`cart_id` = 1 AND `items`.`id` = 13

这是我的代码

before_action :current_cart

private

def current_cart
  if session[:cart_id]
    cart = Cart.find_by(:id => session[:cart_id])
    if cart.present?
      @current_cart = cart
    else
      session[:cart_id] = nil
    end
  end

  if session[:cart_id] == nil
    @current_cart = Cart.create
    session[:cart_id] = @current_cart.id
  end
end

protected

def configure_permitted_parameters
  devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name,:last_name])
end

0 个答案:

没有答案