2016-05-21 10 views
0

このチュートリアルの手順は次のとおりです。http://guides.rubyonrails.org/getting_started.html 記事を削除する際に問題があります。私はチュートリアルが示すようにコードを書いていますが、リンクを 'Destroy'にしましたが、クリックすると記事の確認や削除を要求する代わりに記事のページが表示されます「ショー」をクリックしたときのようなもの。これは私のコードの中で私が欲しいものを実行できない場所です:Railsチュートリアル:deleteメソッドが機能しない

<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> 

私は助けていただきありがとうございます!

ArticlesController内部destroy方法:

def destroy 
    @article = Article.find(params[:id]) 
    @article.destroy 
    redirect_to articles_path, alert: "Article successfully deleted" 
end 

routes.rbを:これは私が、私は、それはとても長いですごめんなさい(Destroyリンクをクリックした後、ログがある

Rails.application.routes.draw do 
    get 'welcome/index' 
    resources :articles 
    root 'welcome#index' 
end 

最も重要なことを知らない):

Started GET "/articles/1" for ::1 at 2016-05-23 14:22:16 +0300 
Processing by ArticlesController#show as HTML 
Parameters: {"id"=>"1"} 
Article Load (0.0ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT 1 [["id", 1]] 

Rendered articles/show.html.erb within layouts/application (1.0ms) 
Completed 200 OK in 136ms (Views: 92.3ms | ActiveRecord: 0.0ms) 

Started GET "/stylesheets/default.css" for ::1 at 2016-05-23 14:22:16 +0300 
ActionController::RoutingError (No route matches [GET] "/stylesheets/default.css"): 

actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call' 
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch' 
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call' 
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app' 
railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call' 
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged' 
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged' 
railties (4.2.6) lib/rails/rack/logger.rb:20:in `call' 
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' 
rack (1.6.4) lib/rack/runtime.rb:18:in `call' 
activesupport (4.2.6)  lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call' 
rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
railties (4.2.6) lib/rails/engine.rb:518:in `call' 
railties (4.2.6) lib/rails/application.rb:165:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
rack (1.6.4) lib/rack/content_length.rb:15:in `call' 
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread' 

Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (2.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (2763.6ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (1896.9ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (4376.6ms) 


Started GET "/javascripts/default.js" for ::1 at 2016-05-23 14:22:25 +0300 

ActionController::RoutingError (No route matches [GET] "/javascripts/default.js"): 
    actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call' 
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch' 
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call' 
actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app' 
railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call' 
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged' 
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged' 
railties (4.2.6) lib/rails/rack/logger.rb:20:in `call' 
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' 
rack (1.6.4) lib/rack/runtime.rb:18:in `call' 
activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call' 
rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
railties (4.2.6) lib/rails/engine.rb:518:in `call' 
railties (4.2.6) lib/rails/application.rb:165:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
rack (1.6.4) lib/rack/content_length.rb:15:in `call' 
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run' 
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread' 


Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (2.5ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.5ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (2777.2ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (1912.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (1.0ms) 
Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (4408.9ms) 
+0

これはjs関連の問題だと思われます – Thorin

+0

ヒットボタンをクリックするとサーバーコンソールのログを追加できますか?削除方法で投稿されていないようですが、 – Thorin

+0

ブラウザでjsを有効にしていますか? –

答えて

-1

def destroy 
    @article = Article.find(params[:id]) 
    @article.destroy 
    redirect_to articles_path, alert: "Article successfully deleted" 
end 
+0

チュートリアルで推奨されているとおりです。 –

+1

あなたはそれを更新する前にあなたの質問に言及していませんでした。特にあなたの質問を更新するために自分のコードを使用している場合は、そのためにdownvoteするべきではありません。 – Yimanei

+0

それは私がダウン投票した私ではなかった、なぜ私はこれについてのすべての答えがdownvotedになっているのか分かりません。 –

-1

削除リンクがRails ujsに依存している:ローラーあなたは、このようなdestroyメソッドを持つ必要があります。あなたのブラウザでJavaScriptが有効になっていますか?

+0

はい、javascriptが有効です。 –

+0

あなたのアプリケーションでは、js: '// = jquery_ujsが必要ですか? – Fred

+0

はい、自動的に生成されました。 –

関連する問題