search for: for_product

Displaying 19 results from an estimated 19 matches for "for_product".

2007 Aug 30
3
Rails - depot application
...quot;Extracted source (around line #9): 8: for item in @items 9: product = item.product 10: -%> 11: <tr> 12: <td><%= item.product%></td>" this is display_cart.rhtml line_item.rb has: "class LineItem < ActiveRecord::Base belongs_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 &lt...
2005 Dec 14
9
Passing quantity in a shopping cart
I am using this line on my index.rhtml page to capture the quantity required of a particular item for a basic shopping cart app: <%= text_field ''line_item'', ''quantity'', {:size=>3} %> </td> but my next screen (a cart screen) doesn''t reflect what was entered in that text field when the item is added to the cart. That is,
2006 Feb 27
1
Odd problem in Agile tutorial
...---------------------- 1 class Cart 2 3 attr_reader :items 4 attr_reader :total_price 5 6 def initialize 7 @items = [] 8 @total_price = 0.0 9 end 10 11 def add_product(product) 12 # @items << LineItem.for_product(product) 13 item = @items.find {|i| i.product_id == product.id} 14 if item 15 item.quantity += 1 16 else 17 item = LineItem.for_product(product) 18 @items << item 19 end 20 @total_price += product.price 21 en...
2006 Aug 13
3
Logging in Rails
...ching 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 else @items << LineItem.for_product(product) end @total_price += product.price end end ------------------------------------- Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060813/4add1dbd/attachment.html
2006 Jul 27
1
no method??
Whenever i type what the book says which is... xml.order_list(:for_product => @product.title) do for o in @orders xml.order do xml.name(o.name) xml.email(o.email) end end end it gives me this error that says... NoMethodError in Info#who_bought You have a nil object when you didn''t expect it! The error occured while evaluating nil.title Extract...
2006 Feb 12
0
no method error - you have a nil object....
...controllers/store_controller.rb:1 code (with my some of my own comments as follows). once again, thanks in advance: class Cart attr_reader :items attr_reader :total_price def initialise @items = [] @total_price = 0.0 end def add_product(product) @items << LineItem.for_product(product) #uses helper class method "for_product" in model: line_item.rb, which creates a line_item based on a given product @total_price += product.price end end ===== class StoreController < ApplicationController def index # calls salable_items function in the controller...
2006 Feb 26
0
NoMethodError in Agile Web Devleopment Depot Tutorial
...cart.items end private def find_cart session[:cart] ||= Cart.new end end =============================== #cart.rb 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 =============================== #line_item.rb class LineItem < ActiveRecord::Base belongs_to :product def self.for_product(product) item = self.new item.quantity = 1 item.product = product item.unit_price = product.price...
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_item.rb class StoreController < ApplicationCon...
2006 Aug 07
0
Re:
...it''s the syntax of the book. Has anyone seen the errata or >have any ideas? I would think that if we''re getting the same results, >surely there''s someone else out there who knows what''s going on. I had similar problems, turns out in the method LineItem#for_product the last line for me was "item.unit_price = product.price", so this was returning the float rather than the "item" object itself. All you need is to add a line "item" which would return the object rather than the float - class LineItem < ActiveRecord::Base b...
2006 Aug 02
7
Same error ... again.
...#This new cart is then returned. end end [CODE] and finally my cart.rb which rests in app/models: [CODE] 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 [CODE] What is the problem that it gives me that float error? Eeverything seems to be in order. -- Posted via http://www.ruby-forum.com/.
2006 Jan 19
3
Troubleshooting Depot App
...l variable or method `product'' for LineItem:Class RAILS_ROOT: script/../config/.. Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:991:in `method_missing'' #{RAILS_ROOT}/app/models/line_item.rb:7:in `for_product'' #{RAILS_ROOT}/app/models/cart.rb:11:in `add_product'' ./script/../config/../app/controllers/store_controller.rb:10:in `add_to_cart'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:991:in `method_missing'' /usr/local/lib/ruby/gems...
2006 Jun 23
3
Yet another problem with NoMethodError in Store#display_cart
...ine_item end <--- file application.rb end here ---> <--- file cart.rb begin here ---> 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 <--- file cart.rb end here ---> <--- file line_item.rb begin here ---> class LineItem < ActiveRecord::Base belongs_to :product def self.for_product(product) item = self.new item.quantity = 1...
2006 Feb 01
1
Problems with sample code from "agile webdev. w. rails"
...#------------- class Cart attr_reader :items attr_reader :total_price def initialize @items = [] @total_price = 0.0 end def add_product(product) item = @items.find { |i| i.product.id == product.id } if item item.quantity += 1 else item << LineItem.for_product(product) # <<<<<<<< this is line 17 @items << item end @total_price += product.price end end #------------- I get the following error when I want to add a product to the shopping cart #---------------- NoMethodError in Store#add_to_cart You hav...
2006 Jan 05
0
question about Agile Rails
...uct.i all of these 2 notation works , but i find the second s more clean. Any explanation will be fine Regards def add_product(product) item = @items.find {|i| i.product_id == product.id} //and why not i.product.id if item item.quantity +=1 else @items << LineItem.for_product(product) end @total_price += product.price end end -- The Crocodile
2006 Jan 25
2
Agile tutorial
...n item already # exists for that product, up the count instead def add_product(product) item = @items.find {|i| i.product_id == product.id} if item item.quantity += 1 else item = LineItem.for_product(product) @items << item end @total_price += product.price end end Is there any other place that I should be looking? What I am getting for output is this: Display Cart Your cart currently holds 2 items. 1.0 Development Produ...
2006 Aug 15
3
update or alter cart
I want to modify and update the items in the Depot - "display_cart". Since the cart is in a session, its a little hard to get at the data. I just want to create a way to change quantities, prices and recalculate. Has someone done this, and could you point me to the right direction. Thanks Chas -- Posted via http://www.ruby-forum.com/.
2006 Mar 05
3
"Undefined method" problem in "Agile Web Development With Rails"
Hi, I''m reading the "Agile Web Development With Rails" book. So long, everything has worked fine, but now I got this annoying error message that I just can''t understand. The error appears for me around page 87, chapter 8. NoMethodError in Store#display_cart Showing app/views/store/display_cart.rhtml where line #28 raised: undefined method `product''
2007 Oct 19
14
Agile Web Development Book, need a bit of help
I''m working my way through the book Agile Web Development with Rails, and I am in the section where the book has me creating a display_cart method and the associated view. When I copied the code from the book into the view, it threw this error. If anyone could give me some hints where I should be looking I''d appreciate it. NoMethodError in Store#display_cart Showing
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''