Hi guys!
I’m doing a shopping cart with the gem: gem act_as_shopping_cart (
GitHub - crowdint/acts_as_shopping_cart: Simple Shopping Cart implementation, Official repo: https://github.com/dabit/acts_as_shopping_cart)
This gem do not have a good documentation, butis popular.
in my action add_item I’m getting the error:
No route matches {:action=>“add_item”, :id=>nil, :controller=>“comprar”}
This is my controller to items:
class ComprarController < SuperSiteController
def index
@v = Video.order(‘created_at asc’)
@n = News.all
@cat = Category.all
end
def show
@v = Video.find(params[:id])
@n = News.all
@cat = Category.all
@cart = Cart.new
end
def add_item
@cart = Cart.create
@product = Video.find(params[:id])
@cart.add(@product, @product.week_price)
end
end
the model to my cart:
class Cart < ActiveRecord::Base
attr_accessible :id, :owner_id, :owner_type, :quantity,
:item_id, :item_type, :price
acts_as_shopping_cart_using :video
end
the model to items to sell:
class Video < ActiveRecord::Base
attr_accessible :active, :desc, :embed, :img1, :img1_uid,
:img2, :img2_uid, :img3, :img3_uid, :img4,
:img4_uid, :infos, :month_price, :slug, :title,
:trailer, :views, :week_price, :year_price, :category_id
belongs_to :category
acts_as_shopping_cart_item_for :cart
end
and the code in my view “show”:
<% form_for @cart, :url => {:action => “add_item”, :id => @cart.id} do
|f|
%>
<%= f.submit ‘Add to Cart’ %>
<% end %>
Someone is seeing something that I’m not?
I following the documentation, but still get this error
Add Items
To add an item to the cart you use the add method. You have to send the
object and the price of the object as parameters.
So, if you had a Product class, you would do something like this:
@cart = Cart.create
@product = Product.find(1)
@cart.add(@product, 99.99)
Thanks!
–
Fernando A.