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


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

  def find_cart
     #session[:cart] ||=
     session[:cart] = #<------********

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:


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

rake db:rollback

and then doing:


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.


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:


Here is the add_to_cart action:

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

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

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


  def find_cart
    session[:cart] ||=

7stud -- wrote:

  def find_cart
    session[:cart] ||=

If I change that method to:

def find_cart

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

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

  def find_cart
    session[:cart] ||=

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:

$ git log
commit 1964b4f78d82da730ccf5fc6d1ba7d1e1b5ae266
Author: me