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.
Related
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 :)
I am trying to install and use Stylus in a brand new rails app.
First, I've created a new rails app: rails new try-stylus
Then, I've run the command: sudo npm install stylus
And, I've added gem 'stylus' to my Gemfile, and run bundle to install it.
In application.rb at the end of Application < Rails::Application class, I've added:
if defined?
Stylus.debug = Rails.env != "production"
end
I've renamed application.css to application.styl and edit its content:
//= require_tree .
//= require_self
body
background red
I've created a simple PageController with an index action rendering an Hello world template index.html.erb.
Eventually, I've run rails s.
And got the following error in my browser:
Showing /.../app/views/layouts/application.html.erb where line #5 raised:
ExecJS::ProgramError in Pages#index
TypeError: undefined is not a function
Where line 5 is:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
Do you have any clue?
Confused at what to do. Default rails install by the RailsInstaller.
started a new demo app. Using rails 3.2.14.
created a controller
rails generate controller Say hello goodbye
However whenever I navigate to the localhost it returns an execjs error.
So for
http://localhost:3000/say/hello
I received
ExecJS::RuntimeError in Say#hello
Showing c:/work/demo/app/views/layouts/application.html.erb where line #6 raised:
(in c:/work/demo/app/assets/javascripts/say.js.coffee)
Extracted source (around line #6):
3: <head>
4: <title>Demo</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
Rails.root: c:/work/demo
I have tried searching for solutions but the only one I thought seemed applicable hasn't helped.
I added to my gemfile the below and did bundle update. No Success.
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
What should I do?
EDIT
gemfile.lock http://pastebin.com/hGPJpxLp
Find ExecJS's runtimes.rb file.
bundle show execjs
Make a backup. Open the runtimes.rb and edit. Find the part that starts with the line JScript = ExternalRuntime.new(. On the line containing :command => "cscript //E:jscript //Nologo //U", - remove the //U only. Now in the line containing :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE - change UTF-16LE to UTF-8 . Save changes. Result should be like:
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-8' # CScript with //U returns UTF-16LE
)
restart rails s, problem should be solved.
Use gem install node .
I don't know why this works but it works .
Make sure you have gem 'therubyracer' and gem 'execjs' under assets group then run bundle install , also you can try Node.js instead of execjs
I also had a problem, After the R&D I installed node.js (http://nodejs.org/download/) the problem become solved.
adding the gem gem 'execjs' did it for me.
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>
I've created a clean and simple Rails 3.1 application called demo1. It contains two controllers - hello and goodbye. I get the following error when I try to load http://localhost:3000/say/hello:
ActionView::Template::Error (
(in /home/me/dev/ruby/demo1/app/assets/javascripts/say.js.coffee)):
3: <head>
4: <title>Demo1</title>
5: <%= stylesheet_link_tag "application" %>
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___558576499_89622220'
The problematic line of application.html.erb is:
<%= javascript_include_tag "application" %>
When I created the application using Rails 3.0 this particular line was:
<%= javascript_include_tag :defaults %>
And this worked fine. In fact, when I change the application.html.erb to use :defaults everything works, but I want to use the new features of Rails 3.1.
I can't seem to turn up anything on Google around this, I guess because Rails 3.1 has just been released.
By the way, I'm following the first chapter in the Agile Web Development with Rails (4th edition) Updated for Rails 3.1 book.
Some environmental info that may help in answering this question:
$ cat /etc/issue
Ubuntu 10.04.2 LTS \n \l
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
$ rails -v
Rails 3.1.0
Contents of the say.js.coffee file:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Ok, I've figured out what the issue was, and so I'll answer my own question.
The problem was the app/assets/javascripts/application.js file contained commented out code. However, one of the commented out lines was as follows:
//= require_tree .
When I delete this line everything works fine.
Hope this helps. If someone can provide some insight as to why the underscore was causing the issue that would be great.
I just ran into this issue when starting a new RoR 3.2.1 app. The problem is that you are missing a JS runtime, which is because the line
# gem 'therubyracer'
in your Gemfile has that # in front of it. God only knows why they ship Rails with that line commented, because any tutorial that uses generate scaffold or similar will result in the asset compilation process tripping up over the generated coffeescript file.
The solution is to uncomment that line. Installing another JS runtime may also solve the problem. See e.g. ExecJS and could not find a JavaScript runtime.
The official ruby on rails guide says:
Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an execjs error. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to Gemfile in apps generated under JRuby. You can investigate about all the supported runtimes at ExecJS.
Simply delete the 2 lines from application.js
//= require turbolinks
//= require_tree
I had the same problem running rails 3.1.1
Once I reinstated the following code in my Gemfile, my issue disappeared:
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
This was placed in my Gemfile when initially setting up the project, i.e. using "rails new myapp".
Note that the in my template file I include:
<%= javascript_include_tag :application %>
Hope that helps
If you're on Windows and you used RailsInstaller to get your development going, you need to use that .bat file included with RailsInstaller to run your server. Also you can't use any CMD hook like conemu to start the server, unfortunately.
For the benefit of future Googlers, I went down a rabbit hole trying to install therubyracer until I stumbled upon this related post:
ExecJS::RuntimeError in rails 3.2.8 engine with javascript_include_tag
The link mentioned explains that ExecJS is configured incorrectly for Windows 8 out-of-the-box. In particular, the workaround described by pottsk did the trick for me.
https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952
It involves changing the way that the cscript executable is run by ExecJS in %rubyinstall%\gems\2.0.0\gems\execjs-2.0.1\lib\execjs\runtimes.rb:
# JScript = ExternalRuntime.new(
# :name => "JScript",
# :command => "cscript //E:jscript //Nologo //U",
# :runner_path => ExecJS.root + "/support/jscript_runner.js",
# :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
# )
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-8' # CScript with //U returns UTF-16LE
)
It goes without saying that this is not a permanent solution but it does get me up and running until the patch is incorporated.
Removing //= require_tree will just stop your javascript files from being loaded into rails. It will probably stop the error, but probably not what you'd like.
However, in my case, I had some .js.coffee files with incorrect indenting. Once I fixed this (by deleting them), it worked.
Another thing you can try which worked for me is to add the json (and perhaps also the yajl-ruby) gem to your Gemfile. I don't really understand why they weren't already installed before because:
rails depends on actionpack
which depends on sprockets
which depends on json and tilt
and tilt depends on yajl-ruby
Yet, somehow, it seems many of the dependent gems were not installed!?
In case of using linux(Ubuntu linux like mine), install javascript runtime. The best is issue the below command to install,
apt-get install nodejs
or else, for each and every new creation of rails project, add
gem 'therubyracer' to your gemfile and run bundle install
devise_scope :user do
get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end
If your routes.rb has this above line just delete it and run. This is what corrected my problem.
modify generator file (application.html.erb.tt) as the following:
<%= javascript_include_tag "application", "data-turbolinks-track" true %>
<%= javascript_include_tag :default, "data-turbolinks-track" true %>
Just REMOVE the following line (Line no. 6) from generator file (application.html.erb) :
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
please update me if there is any drawback to remove this line
Thanks
I have this issue in Rails 4, and if I switch it to 'defaults' rather than 'application', it works, just as the OP says. But this is in an external Gem that I'd rather not edit. I have found that if I force my Gemfile to use version 1.8.0 of coffee-script-source, do a bundle install, and start the server, then everything works fine.
Adding the gem 'therubyracer' fixed the issue.
I was getting the error only after adding external js file through <%= javascript_include_tag %>