1

I'm new to Ruby and following http://guides.rubyonrails.org/getting_started.html and am stuck at destroying the article. It won't bring up the dialog to delete but just redirects to the article. Can someone help me delete the article? I know it has to do with javascript but can't figure out. Thanks in advance.

These are my settings:

GEMFILE

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
#gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
gem 'execjs'

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', '~> 0.4.0', group: :doc
...

application.html.erb

...
<%= stylesheet_link_tag    'default', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
...

javascript line gave me an execjs error in browser so I changed 'application' to 'default' and it was ok.

application.js

...
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

index.html.erb

...    
<% @articles.each do |article| %>
    <tr>
      ...
      <td><%= link_to 'Destroy', article_path(article),
              method: :delete,
              data: { confirm: 'Are you sure?' } %></td>
    </tr>
  <% end %>
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Mike
  • 149
  • 2
  • 13
  • 1
    `:defaults`, not `'default'` (http://api.rubyonrails.org/v3.2.8/classes/ActionView/Helpers/AssetTagHelper/JavascriptTagHelpers.html) You need to include the proper files and fix the js errors.. – Brad Werth Aug 09 '15 at 06:12
  • changed 'default' to :defaults but it didn't work. also re-installed execjs by 'gem install execjs' and it still doesn't work. I'm using windows, rails version is 4.2.3. Zoran's link seems to be for older versions but I tried everything to no avail. – Mike Aug 09 '15 at 06:37
  • http://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-trying-to-follow-rubytutorial I'm fresh out of close votes for today, but I bet this is what you want... – Brad Werth Aug 09 '15 at 06:42

1 Answers1

0

I see you already have:

gem 'therubyracer', platforms: :ruby
gem 'execjs'

in your Gemfile.

You should just run:

bundle install

to install the gems and re-start the server. Everything should work afterwords!

Alternatively, just install another Javascript runtime library such as Node.js and it should work!

Update

Replace defaults with application in your application.html.erb file and add: gem 'coffee-script-source' to your Gemfile and run: bundle install

Your problem should be fixed by now.

Community
  • 1
  • 1
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
  • commented out gem 'therubyracer' as it seems it's not recommended anymore. 'bundle install' doesn't do anything. it just says 'using ...' and doesn't update. execjs is 2.5.2. How do I install node.js? – Mike Aug 09 '15 at 06:40
  • Are you on Mac OSX? You can follow this link to install node js: https://changelog.com/install-node-js-with-homebrew-on-os-x/ Here is another link which will be helpful for installing node js: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager – K M Rakibul Islam Aug 09 '15 at 06:45
  • Sorry. On Windows 8 64-bit. – Mike Aug 09 '15 at 21:14
  • You should be able to install Node.js on your Windows 8 computer following the instructions from this link: http://blog.garethjmsaunders.co.uk/2013/10/24/installing-node-js-on-windows-8/ Let me know if that helps. – K M Rakibul Islam Aug 09 '15 at 21:32
  • ok I installed node.js and it still doesn't work. What should I do? – Mike Aug 09 '15 at 23:00
  • Did you restart the Rails server? Does it still show the same error? – K M Rakibul Islam Aug 09 '15 at 23:02
  • Yes I rebooted the computer after installing node.js and reopened the cmd prompt to enter 'rails s'. What frustrates me is I don't know what's happening beyond it that I can't troubleshoot. I've been just doing what people are saying, eg take this off, take that off. – Mike Aug 09 '15 at 23:07
  • It's hard to tell without seeing the exact error messages. This link: http://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-trying-to-follow-rubytutorial has some solid discussions on windows platform. You can take a look and see if any one of those work for you. Also, I am on Mac OSX. So, I can't test or reproduce your problem locally. – K M Rakibul Islam Aug 09 '15 at 23:13
  • saw this in console: Started GET "/javascripts/defaults.js" for ::1 at 2015-08-09 16:33:33 -0700 ActionController::RoutingError (No route matches [GET] "/javascripts/defaults.js "): – Mike Aug 09 '15 at 23:35
  • replace `defaults ` with `application ` in your `application.html.erb` file and add `gem 'coffee-script-source', '1.8.0'` to your Gemfile and run `bundle install`. Then try again. – K M Rakibul Islam Aug 09 '15 at 23:53
  • I edited the gemfile and when I bundle install, I get this msg "The bundle currently has coffee-script-source locked at 1.9.1.1. Try running `bundle update coffee-script-source`" Also, after reading [http://api.rubyonrails.org/v3.2.8/classes/ActionView/Helpers/AssetTagHelper/JavascriptTagHelpers.html#method-i-javascript_include_tag], I notice that I don't have any javascript folder in public folder. Is this ok? – Mike Aug 10 '15 at 01:30
  • ok I did the 'bundle update coffee-script-source' and changed to 'application' and it worked. I don't know what triggered it exactly. It may have been the gem coffee-script-source command. Thank you K M Rakibul Islam. – Mike Aug 10 '15 at 02:01
  • Great to hear that it worked for you :) Could you please accept my answer now? – K M Rakibul Islam Aug 10 '15 at 02:03