beginning ruby session problem / how do I rollback with git?

Hi,

Rails 2.3.2

I'm following along with the examples in AWDWR (3rd), and around about
p. 103, where you are working with a session table you created, I
decided to free lance a bit. At some point, I tried to "clear" the
session by doing the following:

class StoreController < ApplicationController
...

private
  def find_cart
     #session[:cart] ||= Cart.new
     session[:cart] = Cart.new #<------********
  end

I figured that would "erase" the old cart, and let me continue with a
new, empty cart. However, everything is completely messed up now, and
when I try to access a "store page" (which lists the products for sale)
using the following url:

http://localhost:3000/store

I get an error page that says:

  We're sorry but something went wrong.
  We've been notified about this issue and
  we will take a look at it shortly.

As a fix, I tried rolling back the migration that created the session
table:

rake db:rollback

and then doing:

db:migrate

but I get that same error page. So I'm stuck. So much for free
lancing. Is there some obvious way I can get rid of that error page and
get sessions working again.

Alternatively, I have git installed and I committed my changes at the
end of the last chapter(p. 96). But I've read several git tutorials,
and I can't figure out how to rollback to a previous version of my code.

Thanks.

7stud -- wrote:

Sorry, I can access the store page. It's when I click a button that
calls an add_to_cart action that I get that error message. This is the
url after I click on the add_to_cart button:

http://localhost:3000/store/add_to_cart/5

Here is the add_to_cart action:

class StoreController < ApplicationController
  def index
    @products = Product.find_products_for_sale

    now = Time.now
    @date = now.strftime("%m/%d/%Y")
    @time = now.strftime("%I:%M%p")
  end

  def add_to_cart
    product = Product.find(params[:id])
    @cart = find_cart
    @cart.add_product(product)

  end

private
  def find_cart
    session[:cart] ||= Cart.new
  end
end

7stud -- wrote:

private
  def find_cart
    session[:cart] ||= Cart.new
  end

If I change that method to:

def find_cart
    Cart.new
end

then clicking on an "add to cart" button no longer shows me the error
message. I get a view that lists what was added to the cart. However,
without sessions the view just shows the current item that is being
added.

As soon as I add back the line that mentions sessions:

private
  def find_cart
    session[:cart] ||= Cart.new
  end

I get the error message.

I tried rolling back the migration again:

rake db:rollback

then deleting the migration file:

/depot/db/migrate$ 20090423153751_create_sessions.rb

then recreating the migration file:

/depot$ rake db:sessions:create

and recreating the table:

/depot$ rake db:migrate

then restarting the server. But that did not solve my problem.

I figured out how to rollback with git from this website:

http://www-cs-students.stanford.edu/~blynn/gitmagic/ch02.html#_advanced_undo_redo

$ git log
commit 1964b4f78d82da730ccf5fc6d1ba7d1e1b5ae266
Author: me