ExecJS::ProgramError in Rails tutorial demo app - ruby-on-rails

I'm following demo app tutorial on http://ruby.railstutorial.org/chapters/a-demo-app#sec:planning_the_application. After generate scaffold for users. when i try to access localhost:3000/users. I got the following error on ExecJS
Started GET "/users" for 127.0.0.1 at 2012-08-01 13:35:37 -0500
Connecting to database specified by database.yml
Processing by UsersController#index as HTML
User Load (0.1ms) SELECT "users".* FROM "users"
Rendered users/index.html.erb within layouts/application (3.1ms)
Completed 500 Internal Server Error in 458ms
ActionView::Template::Error (ExecJS::ProgramError
(in /Users/kylec/apps/demo_app/app/assets/javascripts/users.js.coffee)):
3: <head>
4: <title>DemoApp</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___642905557_18993590'
app/controllers/users_controller.rb:7:in `index'
The page renders if I take out #line 6 <%= javascript_include_tag "application"%>
I'm running ruby 1.9.3, rails 3.2.7, osx 10.5.8

You need to look in your Gemfile. Find this line and uncomment it.
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby

I have faced with similar problem.
I have installed node.js and add path to ruby and it worked.

In my case this was the solution:
I just modified gemfile downgrading coffee-script-source to 1.8.0, and voila! Here is my gemfile:
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# Downgrade coffee-script source
gem 'coffee-script-source', '~>1.8.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'

If you are working on windows, this definitely works :
In your /app/views/layouts/application.html.erb line 5 and 6, change the first parameter application to default.
I met the same problem, too for my situation, I don't know why, but it only happen on Windows. The parameter application works on web server.

For Windows:
In your /app/views/layouts/application.html.erb line 5 and 6, change the first parameter application to default.
I met the same problem also,
it is helped me:
change 'application' for 'default'
my code:
<!DOCTYPE html>
<html>
<head>
<title>AppSample</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>

Related

ExecJS::ProgramError in Welcome#index

On Ubuntu 16.04 with Ruby 2.3.3, Rails 5.0.0.1, and NodeJS 4.2.6 installed, I generated a toy controller with bin/rails generate controller welcome index. After running bin/rails server, I opened http://localhost:3000/welcome/index in my browser to get the following error:
ExecJS::ProgramError in Welcome#index
Showing /rails-app-path/app/views/layouts/application.html.erb where line #7 raised:
ReferenceError: CoffeeScript is not defined
Extracted source (around line #7):
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
This was answered Here
There is a problem in coffe-script-source gem 1.12.1 which was recently updated. the issue is that the source file in this version is empty. there is already an open issue , and it should be fixed soon.
For now you can add this to your GemFile
gem 'coffee-script-source', '= 1.11.1'
and run bundle update coffee-script-source until it's fixed.
As it turned out, a broken version 1.12.1 of the coffee-script-source gem had been uploaded. That version has now been unpublished, so the above hello world app now works (once I rebundled my gems).
ExecJS::ProgramError in Welcome#index error :
It's an easy fix you just have to rename a file,
app/views/layouts/application.html.erb
TO
app/views/layouts/default.html.erb
And then the magic happens :)

ActiveAdmin can't find jquery.ui.datepicker

ActionView::Template::Error (couldn't find file 'jquery.ui.datepicker'
(in /home/raimat/webapps/keita/gems/bundler/gems/active_admin-2ae0a9e09bf9/app/assets/javascripts/active_admin/base.js.coffee:2)):
7: <%= stylesheet_link_tag params[:controller] %>
8: <link rel='stylesheet' href='/assets/typicons.min.css'/>
9:
10: <%= javascript_include_tag "application" %>
11: <%= javascript_include_tag 'ckeditor/ckeditor.js' %>
12:
13:
app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb__42414357695359850_50936120'
app/controllers/home_controller.rb:15:in `index'
This only occurs when I try to deploy my app at webfaction (Both Production and development). I've tried it on two different local machines, and it goes as smooth as it should.
Edit: I removed Gemfile.lock on my local machine, and now I get this error there as well.
Tried the solutions found at rails active admin deployment : couldn't find file 'jquery-ui' but I still stand with the bug.
I use Rails 4.0.2
ActiveAdmin at master branch
I need jquery-rails > ~> 3.1.0 for another gem
Tried adding gem jquery-rails-ui, but still nothing..
Ideas?
I was running into the same problem. Noticed there was an upgrade to jquery-ui-rails a couple of days ago (July 3, 2014) so I downgraded to the previous version and that fixed my problems
In gemfile
gem 'jquery-ui-rails', '~> 4.2.1'
In application.js
//= require jquery-ui

Slim not displaying properly in Rails 4.0.0

I have a sample slim document I am trying to run in my homepage rails app.
My application.html.slim file is as follows:
doctype html
html
head
title Tasks
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
javascript:
alert('Welcome!')
body
= yield
I've added:
gem 'slim-rails'
to my Gemfile, and ran bundle install, and nothing. I've also added:
Slim::Engine.default_options[:pretty] = true
to my confif/environments/development.rb file...and nothing. I just get the output of my application.html.slim file.
I added:
gem 'slim' to my Gemfile, deleted Gemfile.lock, and ran bundle install again, and it worked. Not sure if 'slim-rails' is defunct, or if it requires the slim gem in order to work.

ExecJS::RuntimeError on (essentially) empty new project

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!
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."
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.

Rails Error In Production, may due to link_tag and precompilation

I have installed rails 3.1 with apache2 and passenger on ubuntu 10.04. using ruby 1.9.2 with RVM.
When I load the application in browser in production (development version works fine on my machine), it does not work.
My Production Error Log is:
Started GET "/articles" for 117.230.75.50 at 2011-09-12 13:51:34 +0000
Processing by ArticlesController#index as HTML
Rendered articles/index.html.erb within layouts/application (56.4ms)
Completed 500 Internal Server Error in 126ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>Youexpress</title>
5: <%= stylesheet_link_tag "application" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__385712067674585148_29380260'
app/controllers/articles_controller.rb:7:in `index'
But, when I remove the link_tags in app/views/layouts/application.html.erb like this, the application works fine in production mode.
<!DOCTYPE html>
<html>
<head>
<title>Youexpress</title>
</head>
<body>
<%= yield %>
</body>
</html>
How do I get Around this? When I do bundle exec rake assets:precompile I get the following error:
rake aborted!
no such file to load -- uglifier
(in /home/username/youexpress/vendor/bundle/ruby/1.9.1/gems/jquery-rails-1.0.14/vendor/assets/javascripts/jquery-ui.min.js)
Note: In the above error it shows ruby/1.9.1 not 1.9.2 ( I've installed 1.9.2 )
Please help with my situation.
Thanks
I've found the answer myself, The reason for the error is rails app needs javascript runtime for certain features of sass, coffeescript and uglifier to work.
There are many ways to solve this, by installing javascript runtimes like nodejs
But, the solution I went with, and perhaps the easiest one is, adding gem 'therubyracer' to my Gemfile and then running bundle install
Excerpt from my Gemfile is below
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'therubyracer'
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
adding therubyracer also fixes rake assets:precompile
Hope this helps. I've spent days searching for this solution.

Resources