Forum: Ruby on Rails Can't mass-assign protected attributes: item

6524e86b1a9246d06bc5dd4f2985121d?d=identicon&s=25 Fernando Aureliano (Guest)
on 2014-08-14 23:32
(Received via mailing list)
Hi!

I'm using the version of that
gem https://github.com/crowdint/acts_as_shopping_cart for rails 3

I did evething with ythe convetions names. But I'm getting the error
Can't
mass-assign protected attributes: item

class ShoppingCartsController < ApplicationController

  before_filter :extract_shopping_cart

  def create

    @product = Video.find(params[:product_id])

    @shopping_cart.add(@product, @product.price)

    redirect_to shopping_cart_path

  end

  def show



*Heres my model ShoppingCart*

# == 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



*and the model 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


Someone saw something that I'm not seeing?

Thanks!
34dbedb61632979ce94aaa9c6ae20c04?d=identicon&s=25 Eric Saupe (eric_s21)
on 2014-08-14 23:41
(Received via mailing list)
6524e86b1a9246d06bc5dd4f2985121d?d=identicon&s=25 Fernando Aureliano (Guest)
on 2014-08-14 23:47
(Received via mailing list)
Hi!

Thanks! but if you read the code below, you gonna see that my code is
already have *attr_accessible *for all items.




Em quinta-feira, 14 de agosto de 2014 18h31min12s UTC-3, Fernando
Aureliano
escreveu:
8a17df3426daca6df1afc91e102974a0?d=identicon&s=25 javinto (Guest)
on 2014-08-15 10:24
(Received via mailing list)
Hi,

In the code you posted there is no "attr_accessible :item" is there?

Jan

Op donderdag 14 augustus 2014 23:31:12 UTC+2 schreef Fernando Aureliano:
6524e86b1a9246d06bc5dd4f2985121d?d=identicon&s=25 Fernando Aureliano (Guest)
on 2014-08-15 11:50
(Received via mailing list)
Hi!

I tried, but the error persist.

Em quinta-feira, 14 de agosto de 2014 18h31min12s UTC-3, Fernando
Aureliano
escreveu:
4c6bde00168d595053c09aac7e487f8e?d=identicon&s=25 Colin Law (Guest)
on 2014-08-15 11:53
(Received via mailing list)
On 15 August 2014 10:48, Fernando Aureliano <mail@fernandoaureliano.com>
wrote:
> Hi!
>
> I tried, but the error persist.

Which version of Rails are you using?  If it is 4 then you need to
use strong parameters
http://edgeapi.rubyonrails.org/classes/ActionContr...

Colin
Aa082c8b00a50928e5860dcd70bf2368?d=identicon&s=25 tamouse m. (tamouse_m)
on 2014-08-17 19:00
(Received via mailing list)
On Thu, Aug 14, 2014 at 4:31 PM, Fernando Aureliano <
mail@fernandoaureliano.com> wrote:

> Hi!
>
> I'm using the version of that gem
> https://github.com/crowdint/acts_as_shopping_cart for rails 3
>
> I did evething with ythe convetions names. But I'm getting the error Can't
> mass-assign protected attributes: item
>

I see item_id and item_type in your attr_accessbile list below, but not
item.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.