search for: add_product

Displaying 20 results from an estimated 51 matches for "add_product".

2006 May 19
3
new to rails; problem with testing section in Agile book
...get past an error. this is my cart_test.rb test file: require File.dirname(__FILE__) + ''/../test_helper'' class CartTest < Test::Unit::TestCase fixtures :products def setup @cart = Cart.new end # Replace this with your real tests. def test_add_unique_products @cart.add_product products(:version_control_book) @cart.add_product products(:automation_book) assert_equal products(:version_control_book).price + products(:automation_book).price, @cart.total_price assert_equal 2, @cart.items.size end def test_add_duplicate_product @card.add_product products(:version_co...
2006 Jun 25
1
Unit Testing failure
...rs require File.dirname(__FILE__) + ''/../test_helper'' class CartTest < Test::Unit::TestCase fixtures :products def setup @cart = Cart.new @rails = products(:rails_book) @ruby = products(:ruby_book) end def test_add_unique_products @cart.add_product @rails @cart.add_product @ruby assert_equal 2, @cart.items.size assert_equal @rails.price + @ruby.price, @cart.total_price end def test_add_duplicate_product @cart.add_product @rails @cart.add_product @ruby assert_equal 2*@rails.price, @cart.total_price asse...
2006 Aug 04
6
Errors ... errors and errors.
...the code. But now I get a second error and I want to learn to understand to fix them myself. So here is the error. ArgumentError in StoreController#add_to_cart wrong number of arguments (1 for 0) #{RAILS_ROOT}/app/models/cart.rb:15:in `initialize'' #{RAILS_ROOT}/app/models/cart.rb:15:in `add_product'' #{RAILS_ROOT}/app/controllers/store_controller.rb:19:in `add_to_cart'' -e:4 Now, it says as far as I understand it, that it should need 0 arguments instead of 1. But that should be quite impossible, beacause the cart.rb has a def add_product(product) as we shall see later. I do...
2006 Aug 13
3
Logging in Rails
...a class which is not derived from ActionController or ActiveRecord but I want to use logging, I tried require but still logging does not work - This class is located in a file in "model" directory. ------------------------------------ require ''logger'' class Cart def add_product(product) logger.info("Searching for product #{product.id}") <------------DOES NOT WORK item = @items.find {|i| i.product_id = product.id} logger.info("Item to be added is #{item.product_id}") <------------DOES NOT WORK if item item.quantity += 1...
2008 Jul 10
5
Uninitialized constant (controller/model)
...Controller#add_to_cart uninitialized constant StoreController::Cart This is the controller: class StoreController < ApplicationController def index @products = Product.find_products_for_sale end def add_to_cart @cart = find_cart product = Product.find(params[:id]) @cart.add_product(product) end private def find_cart session[:cart] ||= Cart.new end end Amd this is the model class Cart attr_reader :items def initialize @items = [] end def add_product(product) @items << product end end Thanks for the help -- Posted via http://www.ruby-f...
2006 Jul 24
1
Newbie error: undefined local variable or method
...in the wrong direction.) One thing that throws me is that cart_item is a class (CartItem), not a var or a method...??? Code included below for reference. The code starts with the Store controller: def add_to_cart @cart = find_cart @product = Product.find(params[:id]) @cart.add_product(@product) end The add_product method is in the Cart model: class Cart include Reloadable attr_reader :items def initialize @items = [] end def add_product(product) existing_product = @items.find {|item| item.product == product} if existing_product existing_product.increment_qu...
2008 Apr 15
2
NoMethodError in StoreController#add_to_cart
...----------------------------------------- NoMethodError in StoreController#add_to_cart You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.<< E:/InstantRails/rails_apps/depot/app/models/cart.rb:9:in `add_product'' E:/InstantRails/rails_apps/depot/app/controllers/store_controller.rb: 8:in `add_to_cart'' ------------------------------------------------------------------ The contents of cart.rb: --------------------------------------------- class Cart attr_reader :items def initialize @i...
2006 Jul 18
15
Agile Web Developement with Rails
I recently got a copy of the second addition in PDF and got stuck on the Ajax portion using highlighting page 128. While trying to make my cart flash I got an RJS error when I click add to cart. I have gone back and made sure my code matched what was in the book but no help. I sent Dave an email and he rec''d this list. Anybody got any good links for troubleshooting Ajax or maybe have see
2006 Jan 11
6
Help -- NoMethodError in
Hi, I am just learing Rails and I am going through the Agile Web Development with Rails book. I am receiving: NoMethodError in Store#add_to_cart undefined method `add_product'' for #<StoreController:0x3764d80> RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/controllers/store_controller.rb:12:in `add_to_cart'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in...
2009 Feb 18
3
wrong number of arguments (1 for 0)
...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ My controller is ... def add_to_cart if request.post? product_id = params[:product_id] quantity = params[:quantity] account = get_account() error)---> session[:cart] = SessionCart.new(account) if session(:cart).nil? session[:cart].add_product( product_id) if quantity >= 2 and quantity <= 50 for i in 1..quantity-1 session[:cart].add_product(product_id) end end flash[:notice] = ''Your order has been placed.'' redirect_to :action=>''index'' and retur...
2006 Jun 24
1
@version_control_book not available while testing - AWD book 1 page 148
In the page 148 of the AWD book it''s mentioned that the while testing @products and @version_control_book are automatically made available. That''s not the case with me. In my test environment I don''t get those two variables. I was wondering if anything has changed in Rails 1.1 because in the new edition of the book (AWD - edition 2) there is no mention of such
2007 Feb 07
1
The Depot "Add to Cart" sessions question (2.ed agile book)
...application. I have hit a wall when they started talking about the sessions and the exact mechanics of how an item is added to the session. The code looks like this: depot/app/controllers/store_controller: def add_to_cart @cart = find_cart product = Product.find(params[:id]) @cart.add_product(product) end private def find_cart session[:cart] ||= Cart.new end end depot/app/models/cart.rb class Cart attr_reader :items def initialize @items = [] end def add_product(product) @items << product end end depot/app/views/store/add_to_cart.rhtml <h1&gt...
2007 Aug 30
3
Rails - depot application
...to :product def self.for_product(product) item = self.new item.quantity = 1 item.product = product item.unit_price = product.price end end " cart.rb has: "class Cart attr_reader :items attr_reader :total_price def initialize @items = [] @total_price = 0.0 end def add_product(product) @items << LineItem.for_product(product) @total_price += product.price end end " It looks like product = item.product in display_cart.rhtml is pulling out a decimal number not a content array item. But I have no great idea why or how to find out what is being put into...
2006 Feb 12
0
no method error - you have a nil object....
...wing error, which suggests the @items variable is not being populated with any data from LineItem NoMethodError (You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.<<): /app/models/cart.rb:12:in `add_product'' /app/controllers/store_controller.rb:10:in `add_to_cart'' i''ve triple-checked the code, and found the error in the book through the errata, but really am stumped by this error. any suggestions on good troubleshooting techniques . i have tried rake - which says it...
2006 Feb 26
0
NoMethodError in Agile Web Devleopment Depot Tutorial
...you build the ability to add items to the cart. I''m able to get to /store/display_cart/ and it seems items are being added, but if I just click on a link to add an item (/store/add_to_cart/2) it gives me this: NoMethodError in Store#add_to_cart #{RAILS_ROOT}/app/models/cart.rb:10:in `add_product'' #{RAILS_ROOT}/app/controllers/store_controller.rb:11:in `add_to_cart'' Any ideas? Here are various bits of code: =============================== #store_controller.rb class StoreController < ApplicationController def index @products = Product.salable_items end de...
2006 Jan 25
1
Agile arguement error
...d. Request: Parameters: {"id"=>"1"} session dump: --- :cart: !ruby/object:Cart items: [] total_price: 0.0 flash: !ruby/hash:ActionController::Flash::FlashHash {} and the method def: def add_to_cart product = Product.find(params[:id]) @cart = find_cart @cart.add_product(product) redirect_to(:action => ''display_cart'') end
2006 Jan 30
2
Cannot see what I have done wrong.
In the Agile Rails tutorial I am revisiting building a cart. I have followed the steps given in the book to create the class ''Cart'' thus: class Cart attr_reader :items attr_reader :total_price def add_product(product) @items << LineItem.for_product(product) @total_price += product.price end def initialize @items = [] @total_price = 0.0 end end ~ "app/models/cart.rb" I have wired together the other bits in app/controllers/store_controller.rb and app/models/line_...
2006 Mar 13
4
undefined method `validates_presence_of'' for #<ProductsContr
Hi, I am trying to use method `validates_presence_of'' for validating my input fields on form . I m using it in my action class as follows:- ======================= validates_presence_of(params[:product][:quantity]) ====================== But when I am running my application i m getting error like:- ========================= undefined method `validates_presence_of'' for
2006 Apr 18
4
''depot'' tutorial failing on adding to cart
Hi I''m very keen to learn RoR and have been following the Agile Web Development with Rails book (first edition). However, I''ve come across a problem which has had me stumped for days now. After following the instructions up to page 85 I have tried testing the code thus far, as suggested, by adding an item to the cart. But I am getting the following error: --
2007 Oct 15
4
ArgumentError in StoreController#add_to_cart: wrong number of arguments (1 for 0)
...several of topics that stated the same problem but as far as I am, nothing has helped me out yet. Is there something wrong with the Product model? This is in the StoreController and I believe it is all good. def add_to_cart @cart = find_cart product = Product.find(params[:id]) @cart.add_product(product) end Thanks in advance --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To...