Ruby on rails 空车不可用';t工作,购物车会话未销毁,并在视图中一直指向carts/destroy.html.erb,否则显示为模板丢失
我正在学习使用Rails进行敏捷Web开发(第四),正在进行迭代E3:完成购物车。尝试添加Ruby on rails 空车不可用';t工作,购物车会话未销毁,并在视图中一直指向carts/destroy.html.erb,否则显示为模板丢失,ruby-on-rails,rubymine,Ruby On Rails,Rubymine,我正在学习使用Rails进行敏捷Web开发(第四),正在进行迭代E3:完成购物车。尝试添加空购物车按钮时,出现错误 缺少模板 缺少模板carts/destroy、应用程序/destroy和{:locale=>[:en]、:formats=>[:html]、:handlers=>[:erb、:builder、:raw、:ruby、:jbuilder、:coffee]}。在以下位置搜索:“/Users/anil20787/workspace/railsdir/depot/app/views” 基本上
空购物车
按钮时,出现错误
缺少模板
缺少模板carts/destroy、应用程序/destroy和{:locale=>[:en]、:formats=>[:html]、:handlers=>[:erb、:builder、:raw、:ruby、:jbuilder、:coffee]}。在以下位置搜索:“/Users/anil20787/workspace/railsdir/depot/app/views”
基本上,我得到的代码与
因此,我所做的是,尝试在操作之前编辑下的设置购物车部分。不幸的是,没有成功
因此,我根据需要创建了一个carts.destroy.html.erb
文件,并在此html中添加了一个指向我的store\u url
的重定向,内容如下:
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url= store_url">
这是空购物车
按钮:
<%= button_to 'Empty cart', cart_path(@cart), :method => :delete,
:confirm => 'Are you sure?', :remote=> true %>
过滤器链暂停为:设置购物车渲染或重定向
主要问题在这里。您可以按如下方式将其设置为:
before_action :set_cart ,:only => only: [:show, :edit, :update, :destroy]
仅在显示和编辑操作之前使用此set-cart方法调用。您可以在此处添加rails控制台日志以跟踪到底发生了什么吗?Thnx获取回复。对不起…我对这个还不熟悉,但我该怎么向你展示呢?从development.log?服务器日志中提取空的购物车部分-在使用rails启动服务器的地方,您将找到每个进程的日志。在控制台上找到它。并将其添加到问题。保存服务器日志,感谢您的查看。谢谢!但是在更改之后,nil:NilClass的未定义方法“name”
Started DELETE "/carts/1" for 127.0.0.1 at 2016-09-28 16:26:04 +0800
Processing by CartsController#destroy as HTML
Parameters:
{"authenticity_token"=>"3C5rVYL+5WFQZLp5bHquWkYWwp8VbdJXrewHcOM2US4=",
"id"=>"1"}
Cart Load (0.4ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ?
LIMIT 1 [["id", "1"]]
Rendered carts/destroy.html.erb within layouts/application (2.0ms)
LineItem Load (0.4ms) SELECT "line_items".* FROM "line_items" WHERE
"line_items"."cart_id" = ? [["cart_id", 1]]
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE
"products"."id" = ? ORDER BY title LIMIT 1 [["id", 2]]
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE
"products"."id" = ? ORDER BY title LIMIT 1 [["id", 3]]
Product Load (0.4ms) SELECT "products".* FROM "products" WHERE
"products"."id" = ? ORDER BY title LIMIT 1 [["id", 1]]
Rendered line_items/_line_item.html.erb (7.8ms)
DEPRECATION WARNING: :confirm option is deprecated and will be removed from
Rails 4.1. Use 'data: { confirm: 'Text' }' instead. (c
alled from _app_views_carts__cart_html_erb___2408859514053962311_28668160 at
/mnt/c/Users/Alex Xiong/RubymineProjects/work/depot/a
pp/views/carts/_cart.html.erb:13)
Rendered carts/_cart.html.erb (19.3ms)
Filter chain halted as :set_cart rendered or redirected
Completed 200 OK in 157ms (Views: 151.7ms | ActiveRecord: 2.3ms)
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2016-09-28 16:26:05 +0800
Started GET "/javascripts/defaults.js" for 127.0.0.1 at 2016-09-28 16:26:05 +0800
ActionController::RoutingError (No route matches [GET]
"/javascripts/defaults.js"):
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in
`call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in
`call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in
tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in
`call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2)
lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/usr/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Rendered /var/lib/gems/2.2.0/gems/actionpack-
4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
Rendered /var/lib/gems/2.2.0/gems/actionpack-
4.0.2/lib/action_dispatch/middleware/templates/routes/_route.html.erb (2.3ms)
Rendered /var/lib/gems/2.2.0/gems/actionpack-
4.0.2/lib/action_dispatch/middleware/templates/routes/_table.html.erb
(1.1ms)
Rendered /var/lib/gems/2.2.0/gems/actionpack-
4.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
within res
cues/layout (62.0ms)
Started GET "/carts/store_url" for 127.0.0.1 at 2016-09-28 16:26:06 +0800
Processing by CartsController#show as HTML
Parameters: {"id"=>"store_url"}
Cart Load (0.4ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ?
LIMIT 1 [["id", "store_url"]]
Attempt to access invalid cart store_url
Redirected to http://localhost:3000/
Filter chain halted as :set_cart rendered or redirected
Completed 302 Found in 3ms (ActiveRecord: 0.4ms)
Started GET "/" for 127.0.0.1 at 2016-09-28 16:26:06 +0800
Processing by StoreController#index as HTML
Cart Load (0.4ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT
1 [["id", 1]]
Product Load (0.4ms) SELECT "products".* FROM "products" ORDER BY title
Rendered store/index.html.erb within layouts/application (4.2ms)
LineItem Load (0.3ms) SELECT "line_items".* FROM "line_items" WHERE
"line_items"."cart_id" = ? [["cart_id", 1]]
Product Load (0.3ms) SELECT "products".* FROM "products" WHERE
"products"."id" = ? ORDER BY title LIMIT 1 [["id", 2]]
Product Load (0.3ms) SELECT "products".* FROM "products" WHERE
"products"."id" = ? ORDER BY title LIMIT 1 [["id", 3]]
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE
"products"."id" = ? ORDER BY title LIMIT 1 [["id", 1]]
Rendered line_items/_line_item.html.erb (6.5ms)
DEPRECATION WARNING: :confirm option is deprecated and will be removed from
Rails 4.1. Use 'data: { confirm: 'Text' }' instead. (c
alled from _app_views_carts__cart_html_erb___2408859514053962311_28668160
at /mnt/c/Users/Alex Xiong/RubymineProjects/work/depot/a
pp/views/carts/_cart.html.erb:13)
Rendered carts/_cart.html.erb (18.5ms)
Completed 200 OK in 100ms (Views: 95.9ms | ActiveRecord: 2.3ms)
Started GET "/assets/scaffolds.css?body=1" for 127.0.0.1 at 2016-09-28 16:26:06 +0800
Started GET "/javascripts/defaults.js" for 127.0.0.1 at 2016-09-28 16:26:06 +0800
ActionController::RoutingError (No route matches [GET]
"/javascripts/defaults.js"):
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/usr/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Rendered /var/lib/gems/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
Rendered /var/lib/gems/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/routes/_route.html.erb (2.1ms)
Rendered /var/lib/gems/2.2.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.6ms)
Rendered /var/lib/gems/2.2.0/gems/actionpack- 4.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within res
cues/layout (57.8ms)
before_action :set_cart ,:only => only: [:show, :edit, :update, :destroy]