王梦琪的博客

记录技术学习及感悟

8月10日总结

| Comments

今天有两个重要收获:
1.搞明白了参数是如何传递的!
明白了参数的传递路径,重点是怎么取出来,怎么存进去。
2.会看log了,并且搞懂了基础数据库的语法!

Started PATCH "/carts/1/change_quantity" for ::1 at 2016-08-10 18:50:04 +0800
Processing by CartsController#change_quantity as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"fV/6ERuggXqHgOcqr8D478rpk+1tmBGmK4ftHQ8jlEXRSML/ysQq/rAIHelyXzWuQ25ALVXepeSJrHSoS3JieQ==", "cart_item"=>{"quantity"=>"2"}, "id"=>"1"}
DEPRECATION WARNING: `redirect_to :back` is deprecated and will be removed from Rails 5.1. Please use `redirect_back(fallback_location: fallback_location)` where `fallback_location` represents the location to use if the request has no HTTP referer information. (called from change_quantity at /Users/apple1/jdstore/app/controllers/carts_controller.rb:41)
Redirected to http://localhost:3000/carts
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)

这一段的重点内容是参数,其中要在controller取出quantity的值要如下取

@quantity = params[:cart_items][:quantity]
Started GET "/carts" for ::1 at 2016-08-12 18:50:04 +0800
Processing by CartsController#index as HTML
  Rendering carts/index.html.erb within layouts/application
  Cart Load (0.3ms)  SELECT  "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT ?  [["id", 41], ["LIMIT", 1]]
  CartItem Load (0.1ms)  SELECT "cart_items".* FROM "cart_items" WHERE "cart_items"."cart_id" = ?  [["cart_id", 41]]
  Product Load (0.1ms)  SELECT  "products".* FROM "products" WHERE "products"."id" = ? LIMIT ?  [["id", 7], ["LIMIT", 1]]
  Rendered carts/index.html.erb within layouts/application (9.8ms)
   (0.2ms)  SELECT COUNT(*) FROM "products" INNER JOIN "cart_items" ON "products"."id" = "cart_items"."product_id" WHERE "cart_items"."cart_id" = ?  [["cart_id", 41]]
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 1], ["LIMIT", 1]]
  Rendered common/_navbar.html.erb (8.1ms)
  Rendered common/_flashes.html.erb (1.6ms)
  Rendered common/_footer.html.erb (1.1ms)
Completed 200 OK in 83ms (Views: 80.9ms | ActiveRecord: 1.0ms)

这段是基本的数据库语法,比如前两句的意思是筛选出id=41的carts, 在cart_items表中筛选出cart_id=41的cart_items

Comments

comments powered by Disqus