2

I just created an empty application and only generated a StaticPages controller with home, help, about, and contact options, but when I access localhost:3000/static_pages/home, I get an error:

ExecJS::RuntimeError in Static_pages#home

Showing [...]views/layouts/application.html.erb where line #6 raised:


  (in [...]/app/assets/javascripts/static_pages.js.coffee) Extracted source (around line #6):

3: <head> 
4:   <title>TodolistApp</title> 
5:   <%= stylesheet_link_tag "application", :media => "all" %> 
6:   <%= javascript_include_tag "application" %> 
7:   <%= csrf_meta_tags %> 8: </head> 9: <body> Rails.root: [..]

Application Trace | Framework Trace | Full Trace app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__694989846_43803828'

I've looked at a few stackoverflow articles on this same problem, and some recommended installing Node.js, which I have done, but it hasn't done anything. Just to be clear, I have not added any code to any of the static pages views, nor have I added any javascript anywhere.

Also, something interesting is that if I take out line 4 ( <%= javascript_include_tag "application" %>) there is no error. But I assume that if I take this out, the I can't add javascript.

I'd appreciate any help, thanks!

Cluster
  • 5,457
  • 1
  • 25
  • 36
bhsu
  • 392
  • 1
  • 7
  • 17
  • Did you restart the rails server after installing node? – Cluster Feb 27 '13 at 14:34
  • 1
    This ExecJS error is raised mostly because of a syntax error in Coffee Script, `static_pages.js.coffee` seems to be the source of the problem. – MrYoshiji Feb 27 '13 at 14:34
  • @MrYoshiji My static_pages.js.coffee is completely empty (this is a new project, I have added almost nothing). – bhsu Feb 27 '13 at 14:37
  • @Cluster After I installed Node.js, I did restart the rails server. Just to clarify, when I say install Node.js, I just ran the msi installer that I downloaded online. I didn't have to import it into raisl right? – bhsu Feb 27 '13 at 14:39
  • Is it available in your path. I'm pretty sure ExecJS is simply going to want to be able to run `js` from the command line. Your on windows? Doesn't MS bundle a js runtime that ExecJS can use? I was under the impression only linux users had to install a JS runtime for ExecJS – Cluster Feb 27 '13 at 14:43
  • 1
    http://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-7-trying-to-follow-rubytutorial This looks similar, does anything there help you? – Cluster Feb 27 '13 at 14:45
  • @Cluster If I try to run "js" in command-line, itd doesn't work. I am on Windows. I'm not really sure what ExecJS is. Also, I looked at the answer you linked, where they suggest removing a line in appliation.js, and I removed "//require tree .", and it works. But is this the correct fix? I thought that "//require tree ." was important for loading css/javasript and stuff? – bhsu Feb 27 '13 at 14:47
  • It's a debugging step, basically saying there is a problem somewhere else. I normally remove the require_tree and require files on an individual basis. Try doing that and then adding back the files in your app/assets/javascripts one by one until you hit the error again. – Cluster Feb 27 '13 at 14:52
  • ExecJS is a generic interface that Rails uses that allows Rails to interact with various js runtimes without having to know any specific details, like how to run them. – Cluster Feb 27 '13 at 14:53
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/25231/discussion-between-cluster-and-moneydev) – Cluster Feb 27 '13 at 14:55

2 Answers2

0

Try to use "gem 'therubyracer'" in your Gemfile, with installed "therubyracer_for_windows" I did the following (windows 8 64x): 1. Download gem + dll from https://github.com/hiranpeiris/therubyracer_for_windows 2. install this gem (gem instal ...) and move dll-files to "ruby\bin" 3. restart server (rails s, optionally) 4. Then "bundle install" with "gem 'therubyracer'" in my Gemfile works well

Example: "Using sqlite3 (1.3.7) Using therubyracer (0.11.0beta1) Using uglifier (1.3.0) Using webrat (0.7.1) Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed."

kvant0n0
  • 1
  • 1
  • 1
    Can you elaborate on your answer as to how to use this gem? Some examples would make your answer much stronger. – slm Feb 27 '13 at 16:00
  • So are you referring to including in the gem file, then doing "bundle install"? Or do I have to do more ("gem install therubyracer")? – bhsu Feb 27 '13 at 20:10
0

Add this to your gemfile

gem 'therubyracer', :platform => :ruby
gem 'execjs'

Try this,it might works for you. I got somewhat similar error,i resolved using this.

Nikhil Kathuria
  • 461
  • 6
  • 12