Funny enough it now comes with an different error (a step further since
it’s
redirected there), even though no code was changed in the mean time,
saying:
NoMethodError in Store#display_cart
Showing app/views/store/display_cart.rhtml where line #6 raised:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.product
Extracted source (around line #6):
3:
4: <%
5: for item in @items
6: product = item.product
7: -%>
8:
9:
I can’t help to think that an initial value is not set somewhere, since
it
keep talking about a nil object.
Looking forward to your response.
Kind Regards,
Gerard.
On Friday 25 November 2005 20:35, Craig W. tried to type something
like:
Post your method (add_to_cart) body please. I’m guessing that it’s
On 26 Nov 2005, at 10:24, Gerard J. Petersen wrote:
Funny enough it now comes with an different error (a step further
since it’s
redirected there), even though no code was changed in the mean
time, saying:
NoMethodError in Store#display_cart
Could you post your display_cart method here? The change you mention
seems to imply that the add_to_cart method is working now so we
should concentrate our efforts towards the code that makes the app cry.
It sounds like @items is not getting set. Check your display_cart
method in your store_controlled.rb. It should be something like:
def display_cart
@[email protected]
if @items.empty?
redirect_to_index 'Your cart is empty'
end
if params[:context]==:checkout
render :layout => false
end
end
If you are still stuck, put in some debugging lines to see what’s
going on, e.g.
def display_cart
@[email protected]
p @cart.inspect
p @items.inspect
Funny enough it now comes with an different error (a step further since
it’s
redirected there), even though no code was changed in the mean time,
saying:
NoMethodError in Store#display_cart
Showing app/views/store/display_cart.rhtml where line #6 raised:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.product
Extracted source (around line #6):
3:
4: <%
5: for item in @items
6: product = item.product
7: -%>
8:
9:
I can’t help to think that an initial value is not set somewhere, since
it
keep talking about a nil object.
Looking forward to your response.
Kind Regards,
Gerard.
On Friday 25 November 2005 20:35, Craig W. tried to type something
like:
Post your method (add_to_cart) body please. I’m guessing that it’s
This, as far as I understand it, is done voor both Admin and Store
controller
in the application.rb. See below:
class ApplicationController < ActionController::Base
model :cart
model :line_item
end
This makes sure that the models are available to your application
when it tries to restore the session. You still need to set the
variables to an initial value in Cart as shown in page 84, listing
“File 76.”
After this is done you may need to clear out your ruby sessions.
Thanx again for your patience. The variables are being set. When I put
the
following code (page 88) inplace, it seems to work ok this time:
def add_product(product)
item = @items.find {|i| i.product_id == product.id}
if item
item.quantity += 1
else
items = LineItem.for_product(product) @items << item
end @total_price += product.price
end
Can the ruby session info mess with this, because earlier this didn’t
work and
now it does. Note: I now also restarted webrick, removed the ruby
session,
and remove the cookie in the browser.
I now end up with the display_cart method that doesn’t work.
NoMethodError in Store#display_cart
Showing app/views/store/display_cart.rhtml where line #6 raised:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.product
Two more Q’s:
How does it get to the object nil.product?
Is there a way to enable extensive logging, because logfiles are very
usefull.
Thanx very much again for your feedback!
Regards,
Gerard.
On Saturday 26 November 2005 16:58, Craig W. tried to type
something
like:
This makes sure that the models are available to your application Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.net