我有一個軌3.2.13,postgres,紅寶石1.9.3應用程序,並遇到一個問題時,對象似乎暫時保存,然後消失。Rails創建不永久保存
在我的rails控制檯,我做了以下內容:
s = Shop.create(name: "my shop", city:"NY", state: "NY", user_id: 2)
(0.4ms) BEGIN
SQL (1.0ms) INSERT INTO "shops" ("about", "address1", "address2", "city", "created_at", "image", "name", "state", "stripe_shop_token", "updated_at", "user_id", "zip") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING "id" [["about", nil], ["address1", nil], ["address2", nil], ["city", "NY"], ["created_at", Tue, 09 Jul 2013 18:39:40 UTC +00:00], ["image", nil], ["name", "my shop"], ["state", "NY"], ["stripe_shop_token", nil], ["updated_at", Tue, 09 Jul 2013 18:39:40 UTC +00:00], ["user_id", 2], ["zip", nil]]
(0.6ms) COMMIT
=> #<Shop id: 46, user_id: 2, name: "my shop", address1: nil, address2: nil, city: "NY", state: "NY", zip: nil, about: nil, image: nil, stripe_shop_token: nil, created_at: "2013-07-09 18:39:40", updated_at: "2013-07-09 18:39:40">
Shop.all
Shop Load (1.0ms) SELECT "shops".* FROM "shops"
=> [#<Shop id: 46, user_id: 2, name: "my shop", address1: nil, address2: nil, city: "NY", state: "NY", zip: nil, about: nil, image: nil, stripe_shop_token: nil, created_at: "2013-07-09 18:39:40", updated_at: "2013-07-09 18:39:40">]
店鋪出現在控制檯中進行保存。我關閉了我的電腦,然後能夠在控制檯中恢復商店。如果我重新啓動應用程序,該商店似乎仍然可以識別,但是一旦我在應用程序中執行了任何操作,它就不能再找到該商店。如果我直接進入商店視圖,它會顯示商店,直到我更換頁面,然後再找不到商店。
下面是一些服務器日誌文件:
15:00:12 web.1 | Started POST "/__better_errors/2165427460/variables" for 127.0.0.1 at 2013-07-09 14:51:59 -0400
15:00:12 web.1 | Started GET "/" for 127.0.0.1 at 2013-07-09 14:57:45 -0400
15:00:12 web.1 | Processing by HomeController#index as HTML
15:00:12 web.1 | Rendered home/index.html.erb within layouts/application (1.5ms)
15:00:12 web.1 | User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'ZN0O_btNVpCoktAOBlM3OQ' LIMIT 1
15:00:12 web.1 | Shop Load (0.5ms) SELECT "shops".* FROM "shops" WHERE "shops"."user_id" = 2 LIMIT 1
15:00:12 web.1 | Rendered layouts/_header.html.erb (5.7ms)
15:00:12 web.1 | Rendered layouts/_error.html.erb (0.1ms)
15:00:12 web.1 | Rendered layouts/_footer.html.erb (0.6ms)
15:00:12 web.1 | Processing by HomeController#index as HTML
15:00:12 web.1 | Rendered home/index.html.erb within layouts/application (1.2ms)
15:00:12 web.1 | User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'ZN0O_btNVpCoktAOBlM3OQ' LIMIT 1
15:00:12 web.1 | Shop Load (0.9ms) SELECT "shops".* FROM "shops" WHERE "shops"."user_id" = 2 LIMIT 1
15:00:12 web.1 | Rendered layouts/_header.html.erb (6.7ms)
15:00:12 web.1 | Rendered layouts/_error.html.erb (0.1ms)
15:00:12 web.1 | (0.2ms) BEGIN
15:00:12 web.1 | CartOrder Load (0.4ms) SELECT "cart_orders".* FROM "cart_orders" WHERE "cart_orders"."shop_id" = 49
15:00:12 web.1 | Item Load (0.4ms) SELECT "items".* FROM "items" WHERE "items"."shop_id" = 49
15:00:12 web.1 | SQL (0.4ms) DELETE FROM "shops" WHERE "shops"."id" = $1 [["id", 49]]
15:00:12 web.1 | (0.6ms) COMMIT
15:00:12 web.1 | Rendered layouts/_footer.html.erb (7.6ms)
15:00:12 web.1 | Completed 200 OK in 86ms (Views: 82.0ms | ActiveRecord: 3.6ms)
我如此堅持,我甚至不能確定什麼樣的信息將是有益的。
感謝 史蒂夫
你覺得在服務器日誌查詢頁面變化過程中刪除的店? – usha
我添加了服務器日誌,我看到了刪除,它看起來是在它渲染頁腳之前,這是否意味着與頁腳代碼相關,還是將它綁定到以前的渲染? – Steve
@Vimsha,我想我所需要的只是讓你指出顯而易見的事情,那就是我有過的頁腳助手,如果current_user.shop = 0,我有'<如果current_user.shop = nil%>'而不是'<% =無%>' – Steve