def current_order
if current_store.present?
if !session["current_order_id_#{current_store.id}"].nil?
@current_order = current_store.orders.find_by(id: session["current_order_id_#{current_store.id}"])
else
@current_order = current_store.orders.create
end
else
nil
end
end
Ex: to get to a Store#show page, 3 "orders" are created.
Started GET "/21" for ::1 at 2016-08-25 16:10:48 +0800
Processing by StoresController#show as HTML
Parameters: {"store_id"=>"21"}
Store Load (0.1ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
Store Load (0.1ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", 21]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
Product Load (0.3ms) SELECT "products".* FROM "products" WHERE "products"."store_id" = ? [["store_id", 21]]
Rendered stores/show.html.erb within layouts/customer (4.4ms)
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
(0.2ms) begin transaction
SQL (0.3ms) INSERT INTO "orders" ("store_id", "created_at", "updated_at") VALUES (?, ?, ?) [["store_id", 21], ["created_at", "2016-08-25 08:10:49.037060"], ["updated_at", "2016-08-25 08:10:49.037060"]]
(7.6ms) commit transaction
Store Load (0.2ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
Store Load (0.1ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", 21]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
(0.1ms) begin transaction
SQL (0.4ms) INSERT INTO "orders" ("store_id", "created_at", "updated_at") VALUES (?, ?, ?) [["store_id", 21], ["created_at", "2016-08-25 08:10:49.058540"], ["updated_at", "2016-08-25 08:10:49.058540"]]
(1.1ms) commit transaction
(0.2ms) SELECT SUM("order_lines"."quantity") FROM "order_lines" WHERE "order_lines"."order_id" = ? [["order_id", 659]]
Store Load (0.1ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
Store Load (0.1ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", 21]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."slug" = ? ORDER BY "stores"."id" ASC LIMIT 1 [["slug", "21"]]
CACHE (0.0ms) SELECT "stores".* FROM "stores" WHERE "stores"."id" = ? LIMIT 1 [["id", "21"]]
(0.1ms) begin transaction
SQL (0.4ms) INSERT INTO "orders" ("store_id", "created_at", "updated_at") VALUES (?, ?, ?) [["store_id", 21], ["created_at", "2016-08-25 08:10:49.070428"], ["updated_at", "2016-08-25 08:10:49.070428"]]
(1.0ms) commit transaction
OrderLine Load (0.1ms) SELECT "order_lines".* FROM "order_lines" WHERE "order_lines"."order_id" = ? [["order_id", 660]]
Rendered layouts/_cart_text.html.erb (23.8ms)
Rendered layouts/_store_navigation.html.erb (50.2ms)
Rendered layouts/_messages.html.erb (0.1ms)
Completed 200 OK in 206ms (Views: 186.9ms | ActiveRecord: 13.1ms)