Displaying 20 results from an estimated 35 matches for "total_price".
2012 Feb 21
0
nil can't be coerced into BigDecimal Options
...rt</div>
<table>
<% for item in @cart.line_items %>
<tr>
<td><%= item.quantity %>×</td>
<td><%= item.product.title %></td>
<td class="item_price" ><%= number_to_currency(item.total_price)
%></td>
</tr>
<% end %>
<tr class="total_line" >
<td colspan="2" >Total</td>
<td class="total_cell" ><%=
number_to_currency(@cart.total_price) %></td>
</tr>
</tab...
2007 Aug 30
3
Rails - depot application
...ml
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 << 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...
2006 Jan 31
2
asigning values to atributies when source is nil
I want to use something similar to the following:
@total_price += { product.price <> nil ? product.price : 0.0 }
This fails in rails with a "nil can''t be coerced into Float" error.
What is the (most) correct way to do this?
On a related issue, what is the significance of the value 40
following "cart.rb" in the trace sni...
2008 Aug 25
2
maths not working (can't get this)
...e => true}, :order => ''created_at
DESC'', :limit => 100)
end
def discounted_price
factor = case @duration_in_weeks
when 1..4
1.0
when 5..12
0.9
when 13..24
0.8
when 25..47
0.7
else # from 48 and up
0.6
end
total_price * factor
end
def total_price
(@duration_in_weeks * price_per_week) + registration_fee
end
def duration_in_weeks=(duration_in_weeks)
@duration_in_weeks = duration_in_weeks.to_i
end
end
CONTROLLER
------------
class InvoiceController < ApplicationController
def index...
2007 Jan 05
4
How To Spec Controllers with Finders
Given this code (which renders rjs), I''m faced with the fixture-
driven way of spec-ing or mocking. How the heck to you mock this so
the code at line (2) and (4) work right? I''m still struggling with
mocks but it seems like this can be done. Forgive the naivety of this
question.
1. def change_quantity
2. @line_item = LineItem.find_by_id(params[:id])
3. unless
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 a...
2006 Feb 27
2
Find not working
...pe == type }
if item
item.quantity += qnty.to_i
else
if type == ''Fresh''
item = Fresh.for_dish(dish)
else
item = Frozen.for_dish(dish)
end
item.order_id = 1
item.quantity = qnty.to_i
@items << item
end
@total_price += (dish.price * qnty.to_i)
end
The problem line is this:
item = @items.find {|i| i.dish_id == dish.id && i.type == type }
It appears my simple addition has messed it up (Go me!). Simply put the
above never finds a match even when one is there. I am sure it is a
simple syntax proble...
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 Apr 14
3
Updateform with a has_many relationship ?
...ld element.
@order is the current order, which has_many :order_item which in turn
belongs_to :order.
order_item has a field "amount" which should be modified...
What I tried is this below, but I get a undefined method
`order_item.amount'' for #<Order:0x2375764>
<%total_price=0%>
<%@order.order_item.each{|item|%>
<tr class=<%=cycle(''even'',''odd'')%>>
<td><%=item.product.name%></td>
<td><%=text_field ''order'',''order_item.amount'',:size=>3%></td&...
2006 Jun 25
1
Unit Testing failure
...s
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
assert_equal 1, @cart.items.size
assert_equal 2, @cart.items[0].quantity
end
end
Could someone please tell me why I am getting t...
2006 Feb 01
1
Problems with sample code from "agile webdev. w. rails"
...g code which I have from the book. I cant get it
working. I searched a lot on google - and also on the erata pages of the
book publisher but without any luck. I hope someone can help me.
here is the complete Cart class (cart.rb file)
#-------------
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...
2006 Feb 12
0
no method error - you have a nil object....
...ried irb store_controller, which seems fine, except for:
NameError: uninitialized constant ApplicationController
from app/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.pr...
2006 Feb 26
0
NoMethodError in Agile Web Devleopment Depot Tutorial
...redirect_to(:action => ''display_cart'')
end
def display_cart
@cart = find_cart
@items = @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....
2006 Feb 27
1
Odd problem in Agile tutorial
...fined method error in my cart.rb class when trying
to find in an array. I cannot see what my error is. Perhaps a view
more eyes can help me with this:
#---------------------------------------------------------------
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...
2006 Jan 25
2
Agile tutorial
...e code from the book
as carefully as I could and could find no error but to be sure I
then cut and pasted the code file from the rails development site
and obtained the same result.
my app/models/cart.rb file presently looks like this:
class Cart
attr_reader :items
attr_reader :total_price
def initialize
@items = []
@total_price = 0.0
end
# add a product to our list of items. If an item already
# exists for that product, up the count instead
def add_product(product)
item = @items.find {|i| i.produ...
2006 May 19
3
new to rails; problem with testing section in Agile book
...s
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_control_book)
@card.add_product products(:version_control_book)
assert_equal 2*products(:version_control_book).price,
@cart.total_price
assert_equal 1, @cart.items.size
end
end
an...
2006 Dec 07
2
Problem saving parent and children using belongs_to, class_name, and foreign_key
...;PayjunctionOrder",
:foreign_key => "order_id"
...
------------------
----
class StoreController < ApplicationController
def checkout_complete
...
@order = PayjunctionOrder.new
@order.line_items << LineItem.new(:product => product, :quantity =>
qty, :total_price => product.price * qty)
@order.save!
...
------------------
When I try to save, I get:
Mysql::Error: #23000Column ''order_id'' cannot be null: INSERT INTO
line_items (`order_id`, `total_price`, `product_id`, `quantity`)
VALUES(NULL, ''285.0'', 5, 1)
The d...
2006 Jan 19
3
Troubleshooting Depot App
...ms/custom_require.rb:21:in
`require''
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require''
script/server:3
Request
Parameters: {"id"=>"2"}
Show session dump
---
:cart: !ruby/object:Cart
items: []
total_price: 0.0
flash: !map:ActionController::Flash::FlashHash {}
Response
Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"}
================================================================================================
So I am assuming that there is a problem with...
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''
2006 Aug 13
3
Logging in Rails
...ot;) <------------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