小编Kee*_*eic的帖子

分配属性时,必须将哈希作为参数传递

我正在使用Rails 4跟踪敏捷Web开发.章节购物车9购物车创建.当我想更新购物车时,我收到以下错误通知:分配属性时,必须将散列作为参数传递.CartController#更新.

class CartsController < ApplicationController
  include CurrentCart
  before_action :set_cart, only: [:show, :edit, :update, :destroy]
  rescue_from ActiveRecord::RecordNotFound, with: :invalid_cart

  def index
    @carts = Cart.all
  end

  def show
  end

  def new
    @cart = Cart.new
  end

  def edit
  end

  def create
    @cart = Cart.new(cart_params)

    respond_to do |format|
      if @cart.save
        format.html { redirect_to @cart, notice: 'Cart was successfully created.' }
        format.json { render :show, status: :created, location: @cart }
      else
        format.html { render :new }
        format.json { render json: @cart.errors, status: :unprocessable_entity } …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

ruby-on-rails ×1