8.2 Iteration C1: Creating a Cart 7.4 Iteration B4: Linking to the Cart
rake db:sessions:create
(in /home/rubys/git/awdwr/work-192-239/depot)
exists db/migrate
create db/migrate/20100906101112_create_sessions.rb
rake db:migrate
mv 20100906101112_create_sessions.rb 20100301000004_create_sessions.rb
(in /home/rubys/git/awdwr/work-192-239/depot)
== CreateSessions: migrating =================================================
-- create_table(:sessions)
-> 0.0017s
-- add_index(:sessions, :session_id)
-> 0.0006s
-- add_index(:sessions, :updated_at)
-> 0.0007s
== CreateSessions: migrated (0.0032s) ========================================
sqlite3 db/development.sqlite3 .schema
CREATE TABLE "products" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" text, "image_url" varchar(255), "created_at" datetime, "updated_at" datetime, "price" decimal(8,2) DEFAULT 0);
CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
CREATE TABLE "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "session_id" varchar(255) NOT NULL, "data" text, "created_at" datetime, "updated_at" datetime);
CREATE INDEX "index_sessions_on_session_id" ON "sessions" ("session_id");
CREATE INDEX "index_sessions_on_updated_at" ON "sessions" ("updated_at");
CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
edit config/initializers/session_store.rb
# Be sure to restart your server when you modify this file.
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
ActionController::Base.session = {
:key => '_depot_session',
:secret => '601bba4282539677bfb78506441f417bd5473dc15e44d63e02f24371a06cf752e50801749b4dbb15bee2d9949bd01dae88a3e3e62902b8ab0aa79421a9c818d3'
}
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
ActionController::Base.session_store = :active_record_store
edit app/controllers/application_controller.rb
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
end
edit app/controllers/store_controller.rb
private
def find_cart
session[:cart] ||= Cart.new
end
8.2 Iteration C1: Creating a Cart 7.4 Iteration B4: Linking to the Cart