【发布时间】:2014-08-14 21:48:32
【问题描述】:
我正在为 rails 3 使用那个 gem https://github.com/crowdint/acts_as_shopping_cart 的版本
我用约定名称做了所有事情。但我收到错误无法批量分配受保护的属性:项目
class ShoppingCartsController < ApplicationController
before_filter :extract_shopping_cart
def create
@product = Video.find(params[:product_id])
@shopping_cart.add(@product, @product.price) # the error is generated on that line
redirect_to shopping_cart_path
end
我的模型购物车:
# == Schema Information
#
# Table name: shopping_carts
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#
class ShoppingCart < ActiveRecord::Base
acts_as_shopping_cart
attr_accessible :price
#accepts_nested_attributes_for :price
end
我的模型 ShoppingCartItem:
# == Schema Information
#
# Table name: shopping_cart_items
#
# id :integer not null, primary key
# owner_id :integer
# owner_type :string(255)
# quantity :integer
# item_id :integer
# item_type :string(255)
# price :float
# created_at :datetime not null
# updated_at :datetime not null
#
class ShoppingCartItem < ActiveRecord::Base
attr_accessible :owner_id, :owner_type, :quantity, :item_id, :item_type, :price
acts_as_shopping_cart_item
end
谁能帮助我这里缺少什么?
【问题讨论】:
-
您是否尝试将 :item 添加到 attr_accessible ?
-
是的,并且接受_nested_attributes_for
-
把它放在两个模型中,看看它属于哪里
标签: ruby-on-rails ruby ruby-on-rails-3 shopping-cart