Ruby on rails Rails教程入门删除功能不起作用
我一直在关注,除了博客的两个方面外,其他方面都很有效:Ruby on rails Rails教程入门删除功能不起作用,ruby-on-rails,Ruby On Rails,我一直在关注,除了博客的两个方面外,其他方面都很有效: delete函数导航到我要删除的页面,而不是删除它 在我的CMD中,我得到了一系列与布局文件夹中的路由错误相关的渲染错误,但我不确定这是否是一个将在本教程稍后部分中解决的问题 我的问题主要涉及删除链接的非功能性 index.html.erb <h1>My Notes</h1> <%= link_to 'New Note', new_article_path %> <table>
<h1>My Notes</h1>
<%= link_to 'New Note', new_article_path %>
<table>
<tr>
<th>Note Entry Title</th>
<th>Preview</th>
<th colspan="3"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td> #<<< This is the delete code
</tr>
<% end %>
</table>
单击索引页上的“销毁”后的CMD错误日志
Processing by ArticlesController#show as HTML
Parameters: {"id"=>"4"}
Article Load (0.0ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT ? [["id", 4], ["LIMIT", 1]]
Rendering articles/show.html.erb within layouts/application
Rendered articles/show.html.erb within layouts/application (1.0ms)
Completed 200 OK in 81ms (Views: 57.1ms | ActiveRecord: 0.0ms)
Started GET "/stylesheets/default.css" for ::1 at 2017-04-26 13:12:34 -0400
ActionController::RoutingError (No route matches [GET] "/stylesheets/default.css"):
Started GET "/javascripts/default.js" for ::1 at 2017-04-26 13:12:34 -0400
actionpack (5.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'
web-console (3.5.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.2) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.2) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
ActionController::RoutingError (No route matches [GET] "/javascripts/default.js"):
actionpack (5.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'
web-console (3.5.0) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.5.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (3.5.0) lib/web_console/middleware.rb:18:in `catch'
web-console (3.5.0) lib/web_console/middleware.rb:18:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.0.2) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.0.2) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.0.2) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/request_id.rb:24:in `call'
rack (2.0.1) lib/rack/method_override.rb:22:in `call'
rack (2.0.1) lib/rack/runtime.rb:22:in `call'
activesupport (5.0.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.0.2) lib/action_dispatch/middleware/static.rb:136:in `call'
rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
railties (5.0.2) lib/rails/engine.rb:522:in `call'
puma (3.8.2) lib/puma/configuration.rb:224:in `call'
puma (3.8.2) lib/puma/server.rb:600:in `handle_request'
puma (3.8.2) lib/puma/server.rb:435:in `process_client'
puma (3.8.2) lib/puma/server.rb:299:in `block in run'
puma (3.8.2) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.5ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.0ms)
Rendered collection of C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/routes/_route.html.erb [9 times] (3.5ms)
Rendered collection of C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/routes/_route.html.erb [9 times] (3.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.5ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.5ms)
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendering C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.5ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (2775.8ms)
Rendered C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.2/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (3170.5ms)
rails routes命令结果:
C:\Users\Nick\blog>rails routes
Prefix Verb URI Pattern Controller#Action
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
root GET / welcome#index
application.js代码
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
layouts/application.html.erb文件代码:
Rails.application.routes.draw do
#get 'welcome/index' <- commented this out from earlier step in tutorial
resources :articles
root 'welcome#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
<!DOCTYPE html>
<html>
<head>
<title>Scribble</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'default', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
乱涂
下午1:56更新
更改application.js文件中的一些代码似乎缓解了这个问题(从我所知,这显然是一个js加载错误)
从^
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
到^
- 如果我遇到与此主题相关的更多问题,我将继续教程并更新帖子。感谢大家迄今为止的帮助/支持李>
routes.rb
文件以及整个错误消息吗?对于错误消息,如果您可以复制/粘贴而不是截图,这将更有帮助。它以前没有显示确认对话框?这是清晰、格式良好的第一个问题-谢谢@布赖恩-张贴了你要求的两件事。我没想到要复制/粘贴CMD,很抱歉屏幕截图不太可读。@73David我已经测试了你的代码,它工作正常,你做的很好,但是当你点击删除任何记录时,你会得到一个Completed 200 OK
响应,所以,我没有看到错误,只有那些与您的资产相关的,如ActionController::RoutingError(没有路由匹配[GET]“…”)
,您能说明如何添加它们吗?您能发布您的routes.rb
文件以及整个错误消息吗?对于错误消息,如果您可以复制/粘贴而不是截图,这将更有帮助。它以前没有显示确认对话框?这是清晰、格式良好的第一个问题-谢谢@布赖恩-张贴了你要求的两件事。我没想到要复制/粘贴CMD,很抱歉屏幕截图不太可读。@73David我已经测试了你的代码,它工作正常,你做的很好,但是当你点击删除任何记录时,你会得到一个Completed 200 OK
响应,所以,我没有看到错误,仅仅是那些与您的资产相关的,比如ActionController::RoutingError(没有与[GET]“…”匹配的路由)
,您能展示一下如何添加它们吗?
<!DOCTYPE html>
<html>
<head>
<title>Scribble</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'default', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
<%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'default', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>