7stud – wrote:
So it seems like there is something wrong with my database.
I tried rolling back my migrations to the beginning:
/depot$ rake db:migrate VERSION=0
(in /Users/me/2testing/dir1/rails/depot)
== CreateSessions: reverting
– drop_table(:sessions)
-> 0.0014s
== CreateSessions: reverted (0.0016s)
== AddTestData: reverting
== AddTestData: reverted (0.0034s)
== AddPriceToProduct: reverting
– remove_column(:products, :price)
-> 0.0263s
== AddPriceToProduct: reverted (0.0265s)
== CreateProducts: reverting
– drop_table(:products)
-> 0.0010s
== CreateProducts: reverted (0.0012s)
which left me with this:
/depot$ sqlite3 db/development.sqlite3
SQLite version 3.6.13
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite> .mode line
sqlite> select * from sqlite_master;
type = table
name = schema_migrations
tbl_name = schema_migrations
rootpage = 2
sql = CREATE TABLE “schema_migrations” (“version” varchar(255) NOT
NULL)
type = index
name = unique_schema_migrations
tbl_name = schema_migrations
rootpage = 3
sql = CREATE UNIQUE INDEX “unique_schema_migrations” ON
“schema_migrations” (“version”)
type = table
name = sqlite_sequence
tbl_name = sqlite_sequence
rootpage = 5
sql = CREATE TABLE sqlite_sequence(name,seq)
Then I recreated all the tables:
/depot$ rake db:migrate
(in /Users/me/2testing/dir1/rails/depot)
== CreateProducts: migrating
– create_table(:products)
-> 0.0019s
== CreateProducts: migrated (0.0021s)
== AddPriceToProduct: migrating
– add_column(:products, :price, :decimal, {:precision=>8, :scale=>2,
:default=>0})
-> 0.0118s
== AddPriceToProduct: migrated (0.0122s)
== AddTestData: migrating
== AddTestData: migrated (0.0127s)
== CreateSessions: migrating
– create_table(:sessions)
-> 0.0015s
– add_index(:sessions, :session_id)
-> 0.0004s
– add_index(:sessions, :updated_at)
-> 0.0004s
== CreateSessions: migrated (0.0027s)
Then If I use this version of the find_cart method in the store
controller:
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
Cart.new
end
#***********************
end
when I click on my “add to cart” button, a view displays the current
item. However, if I try to use sessions:
#***********************
private
def find_cart
session[:cart] ||= Cart.new
end
#***********************
then I get the error message. The only thing I haven’t tried is to
delete my whole project and start over.