I am currently trying to get Rails to run on my Windows 7 machine and I am having difficulty. I am very new to Rails (inferred by my use of the Getting Started guide) and I am stuck on this:
http://guides.rubyonrails.org/getting_started.html#deleting-articles
Specifically the, you guessed it, confirmation dialog box. It never appears and Rails just utilizes a SHOW route.
Now for the code:
app\assets\javascripts\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 .
app\controllers\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
app\views\articles\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>
and 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 %-->
Now in the command line, when I click the, "link_to," Destroy link, I get:
[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:/...
Note that everything seems normal after:
Rendered C:/
To fix this issue on my own, I have:
- Made sure SQLite is on my machine
- The SQLite gem is installed
- Active scripts are turned on for my web browser (Opera; based on Chromium)
I have followed every piece of advice I could from Stack Exchange and Stack Overflow, including:
Modifying index.html.erb with:
<%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
or:
link_to 'Cancel?', schedule_path(current_user.schedules[0]), :confirm => "are you sure?", :method => :delete
or:
<td><%= link_to 'Destroy', { action: :destroy, id: post.id }, method: :delete, data: { confirm: 'Are you sure?' } %></td>
or:
<td><%= link_to 'Destroy', [comment.post, comment], method: :delete, data: { confirm: 'Are you sure?' } %></td>
- Making sure that because I am on Windows 7, that my CoffeeScript is version 1.8.0 and that I updated the Gemfile as such
- Making sure the gem, "jquery-rails," is included in the Gemfile file
- Using method: destroy instead of method: delete
- My rake routes look as they should. One answer mentioned making sure
bin/rake routes
returned something normal and it does
Making sure the application.js file includes:
//= require jquery
//= require jquery_ujs
(which you can see above that it does)
and nothing, NOTHING, has worked.
The only thing I have tried that has given me ANY success is replacing the link_to
in index.html.erb with button_to
.
But this doesn't produce a confirmation window. It just performs a DESTROY.
I am very confused and I have spent many hours trying to get this to work.
I have found my answers from these links:
- Rails CRUD - Destroy path always routes to the User show page
- Rails-4, ExecJS::ProgramError in Pages#welcome
- Rails, default.js is empty, and jquery and jquery_ujs not loaded
- Rails 4 link_to Destroy not working in Getting Started tutorial
I may be missing a few links and answers, so please feel free to link me to a thread you think I may have missed.
Thank you for reading this MASSIVE wall of text and I hope I can find a solution to my problem soon.