Hi Folks.
I’m implementing a paypal notification as per the Railscast here #142 PayPal Notifications - RailsCasts
This is the code that is run to view the shopping cart:
def current_cart
if session[:cart_id]
@current_cart ||= Cart.find(session[:cart_id])
session[:cart_id] = nil if @current_cart.purchased_at
end
if session[:cart_id].nil?
@current_cart = Cart.create!
session[:cart_id] = @current_cart.id
end
@current_cart
end
Everything seems to be working fine except this. I’m checking the session[:cart_id]
in the navigation to see if I should show a “My cart” link like so:
<% unless (session[:cart_id].nil?) %>
<li> <%= link_to 'My Cart', current_cart_path %> </li>
It hides the link until a cart exists and should again hide that link once the purchase has been made but it is not. It seems to be setting the value back to nil although the link still shows.
Any idea how I should be checking the value of the session variable in the view or is my problem elsewhere?
Thanks.