Can't mass-assign protected attributes: item

56 views
Skip to first unread message

Fernando Aureliano

unread,
Aug 14, 2014, 5:31:12 PM8/14/14
to rubyonra...@googlegroups.com
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!













Eric Saupe

unread,
Aug 14, 2014, 5:39:15 PM8/14/14
to rubyonra...@googlegroups.com

Fernando Aureliano

unread,
Aug 14, 2014, 5:45:50 PM8/14/14
to rubyonra...@googlegroups.com
Hi!

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

javinto

unread,
Aug 15, 2014, 4:23:44 AM8/15/14
to rubyonra...@googlegroups.com
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:

Fernando Aureliano

unread,
Aug 15, 2014, 5:48:54 AM8/15/14
to rubyonra...@googlegroups.com
Hi!

I tried, but the error persist.


Em quinta-feira, 14 de agosto de 2014 18h31min12s UTC-3, Fernando Aureliano escreveu:

Colin Law

unread,
Aug 15, 2014, 5:53:18 AM8/15/14
to rubyonra...@googlegroups.com
On 15 August 2014 10:48, Fernando Aureliano <ma...@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/ActionController/StrongParameters.html

Colin
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/7cc6ad3d-a4d2-4ca8-a91d-ab44cee06bc0%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

tamouse pontiki

unread,
Aug 17, 2014, 1:00:00 PM8/17/14
to rubyonra...@googlegroups.com
On Thu, Aug 14, 2014 at 4:31 PM, Fernando Aureliano <ma...@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.
 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages