Rails指南:入门5.13删除文章:确认对话框不会出现

我目前正试图让Rails在我的Windows 7机器上运行,我有困难。 我对Rails非常陌生(通过使用入门指南推断出来的),我被困在这里:

http://guides.rubyonrails.org/getting_started.html#deleting-articles

具体来说,你猜对了,确认对话框。 它永远不会出现,Rails只是使用SHOW路线。

现在代码:

应用程序\资产\ JavaScript的\的application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // 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. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require jquery_ujs //= require turbolinks //= require jquery.ui.all //= require_tree . 

应用\控制器\ articles_controller.rb

 class ArticlesController < ApplicationController def index @articles = Article.all end def show @article = Article.find(params[:id]) end def new @article = Article.new end def edit @article = Article.find(params[:id]) end def create @article = Article.new(article_params) if @article.save redirect_to @article else render 'new' end end def update @article = Article.find(params[:id]) if @article.update(article_params) redirect_to @article else render 'edit' end end def destroy @article = Article.find(params[:id]) @article.destroy redirect_to articles_path end private def article_params params.require(:article).permit(:title, :text) end end 

应用程序\意见\文章\ index.html.erb

 <h1>Listing Articles</h1> <%= link_to 'New article', new_article_path %> <table> <tr> <th>Title</th> <th>Text</th> <th colspan="3"></th> </tr> <% @articles.each do |article| %> <tr> <td><%= article.title %></td> <td><%= article.text %></td> <td><%= link_to 'Show', 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> </tr> <% end %> </table> 

和app \ views \ layouts \ application.html.erb

 <!DOCTYPE html> <html> <head> <title>Blog</title> <%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'default', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html> <!--%= javascript_include_tag 'application', 'data-turbolinks-track' => true %--> 

现在在命令行中,当我点击“link_to”Destroy链接时,我得到:

 [2015-09-15 18:48:26] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:10 C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:80:in 'eof?' C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:80:in 'run' C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in 'block in start_thread' Rendered C:/... 

请注意,一切似乎正常后:

 Rendered C:/ 

为了解决这个问题,我有:

  • 确保SQLite在我的机器上
  • SQLitegem已安装
  • 我的networking浏览器(Opera;基于Chromium)打开了活动脚本,

我遵循Stack Exchange和Stack Overflow的每一条build议,包括:

修改index.html.erb:

 <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> 

要么:

 link_to 'Cancel?', schedule_path(current_user.schedules[0]), :confirm => "are you sure?", :method => :delete 

要么:

 <td><%= link_to 'Destroy', { action: :destroy, id: post.id }, method: :delete, data: { confirm: 'Are you sure?' } %></td> 

要么:

 <td><%= link_to 'Destroy', [comment.post, comment], method: :delete, data: { confirm: 'Are you sure?' } %></td> 
  • 确保因为我在Windows 7上,我的CoffeeScript是1.8.0版,并且我更新了Gemfile
  • 确保gem文件中包含“jquery-rails”
  • 使用方法:销毁而不是方法:删除
  • 我的耙路看起来应该如此。 一个答案提到,确保bin/rake routes返回正常的东西,它的确如此

确保application.js文件包括:

 //= require jquery //= require jquery_ujs 

(你可以在上面看到它)

没有什么, 没有 ,已经工作。

我试过的唯一一件东西给了我任何成功,用button_toreplaceindex.html.erb中的link_to

但是这不会产生确认窗口。 它只是执行一个DESTROY。

我非常困惑,我花了很多时间试图让这个工作。

我从这些链接find了我的答案:

  • Rails CRUD – 销毁path总是路由到用户显示页面
  • Rails 4,ExecJS :: ProgramError Pages#welcome
  • Rails,default.js是空的,jquery和jquery_ujs没有加载
  • Rails 4 link_to销毁在入门教程中不起作用

我可能会错过几个链接和答案,所以请随时将我链接到您认为可能错过的主题。

感谢您阅读这篇MASSIVE文字墙,希望我能尽快find解决scheme。

我不认为布局正确加载您的JavaScript。

尝试这个。 希望能帮助到你!

应用程序/视图/布局/ application.html.erb

 <!DOCTYPE html> <html> <head> <title>Blog</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html>