My project was working fine, I was tweaking a chart made with chartkick and updating a HTML badge with ActionCable, when suddenly I get this error:
ExecJS::RuntimeError in Pages#create_session
Showing B:/.../app/views/layouts/application.html.erb where line #7 raised:
SyntaxError: [stdin]:14:32: unexpected end of input
Extracted source (around line #7):
5 <%= csrf_meta_tags %>
6 <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>
7 <%= javascript_include_tag 'application', 'chartkick' %>
8 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
10 </head>
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___430303067_44605968'
app/controllers/pages_controller.rb:145:in `render_page'
app/controllers/pages_controller.rb:46:in `create_session'
I googled and found out that this Error means there is a problem with the JavaScript runtime on my system (I'm using Windows 10).
Things I've tried:
Removing //= require_tree . from application.js - doesn't work for me because then all my JavaScript code doesn't work anymore (my project uses ActionCable)
Modifying C:\RailsInstaller\Ruby2.3.0\lib\ruby\gems\2.3.0\gems\execjs-2.7.0\lib\execjs\ runtimes.rb as is detailed here - didn't fix it
Adding 'therubyracer' gem - couldn't install it, this is the error message I got. That's the complete error message and then it's just done. As far as I can tell it can't install because Python 2 is not installed?
As suggested here, I added the gem 'coffee-script-source' - didn't fix it and now I can't remove it because suddenly other gems depend on it? Weird.
I have had Node.js installed ever since I started this project so that can't be it.
I'm using Windows 10, Ruby 2.3.0 and Rails 5.0.2 and this is my current Gemfile.
This is my application.js:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require chartkick
//= require_tree .
I know there have been many posts with this issue, but after trying almost everything I'm kind of lost... Please help! =)
After Ziyan Junaideens pointer I searched all my CoffeeScript files and finally found I had left a method call unfinished... >_<
received: (data) ->
App.online_status. #<--- right here
So what did I learn? Never program when you are dead tired - or you'll spend the whole next day searching for the stupid mistake! ^^*
if you have gem # gem 'therubyracer', :platform=>:ruby
Change to gem 'mini_racer'
Related
I installed Elasticsearch (with searchkick gem) following this tutorial - https://shellycloud.com/blog/2013/10/adding-search-and-autocomplete-to-a-rails-app-with-elasticsearch.
Search is working and now I'm implementing autocomplete function with typeahead.js which I installed using Bower.
However I get the error message:
Sprockets::FileNotFound at /books couldn't find file 'typeahead.js'
I tried to include it in various orders in my assets file, without luck..
However I realized removing turbolinks from application.html.erb solved the problem.
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
This does not seem right... How can I resolve this?
I had this exact same problem. The author named the library with the .js extension added and I assume it has something to do with application.js ignoring the .js part at the end. I had this problem when using rails-assets and once I poked around more in the gem source I saw two .js.js extensions added.
You can add it as so:
//= require typeahead.js.js
Then you can re-enable
'data-turbolinks-track' => true
I'm a noob to Rails and Javascript. I've made an app with nested attributes while following Ryan Bates' Railscasts 196 & 197 (Nested Model Forms).
Everything works fine upto the point where I use Checkboxes to remove fields. But when I use this in my _question_fields.html.erb:
<%= link_to_function 'remove', 'remove_fields(this)' %>
and this javascript function in /assets/javascripts/application.js:
function remove_fields(link) {
$(link).previous("input[type=hidden]").value = "1";
$(link).up(".fields").hide();
}
nothing happens. I've made sure that <%= javascript_include_tag "application" %> is being included in views/layouts/application.html.erb
Javascript Consoles on Firefox (Firebug) & Chrome (Built-in) throw this error when I click on the remove link.
Uncaught ReferenceError: $ is not defined
Am I missing something very basic? Any help would be appreciated. I'm Using Ruby 1.9.3, Rails 3.2.3 & Mongoid 3.1.2.
Okay, the solution (as pointed out by bfavaretto) was simple enough. We need to use the prototype gem and add it's reference in application.js.
1) In your Gemfile, add:
gem 'prototype-rails'
# You might want to comment out #gem 'jquery-rails'
2) In application.js, above everything else, add:
//= require prototype
//= require prototype_ujs
//= require effects
//= require dragdrop
//= require controls
3) Make sure this line is removed/commented in config/enviroments/development.rb:
#config.action_view.debug_rjs = true
4) Run Bundler and restart Rails Server
$ bundle install
$ rails s # This is important!
I'm trying to get the best-in-place gem to work on a Rails 3.0 app but nothing seems to work. I can't click on any of the objects to edit them.
This is what I've done so far (following the GitHub instructions from the link above as well as the RailsCast:
In my Gemfile:
gem 'rails', '3.0.11'
gem 'best_in_place', '~> 0.2.0'
I also ran rails g best_in_place:setup since I'm on 3.0 and it generated a best_in_place.js file into public/javascripts.
And finally to display the records to be edited in-place:
<div class="profileGains">"<%= best_in_place #project, :my_quote %>"</div>
I'm using RESTful routes so I have the update action for my project resource.
At this point, the record is displayed but I can't click on it (or any of the other ones).
Any suggestions? I'm new to JS and really stuck.
EDIT: I created an application.js file in which I added the following code:
//= require jquery
//= require jquery.purr
//= require best_in_place
$(document).ready(function() {
/* Activating Best In Place */
jQuery(".best_in_place").best_in_place();
});
I also tried the suggestion in the comments by Richlewis to add a script tag in my view:
<script type="text/javascript" src="/public/javascripts/best_in_place.js"></script>
Finally, I tried changing <%= javascript_include_tag :defaults %> to
<%= javascript_include_tag :all %> in my application.html.erb layout file.
And again, best-in-place doesn't work.
UPDATE: When inspecting the element using Chrome I found this error displayed in the logs:
Uncaught TypeError: Object [object Object] has no method 'best_in_place'
application.js line 7
Any idea what this means?
Answering my own question as I figured it out. The best_in_place.js file wasn't being rendered in my view because this code //= require best_in_place only works for apps with an asset pipeline.
I had to explicitly declare the best_in_place.js file in my application layout file. That did the trick.
I'm following the demo_app in Michael Hartl's book Ruby on Rails 3 Tutorail. The demo is a simple Scaffold User name:string email:string
I'm getting an error in my application.html.erb file:
Errno::EINVAL in Users#index
Showing ~/demo_app/app/views/layouts/application.html.erb where line #6 raised:
Invalid argument - cscript //E:jscript //Nologo //U /tmp/execjs20120323-4388-1an85xw-0.js 2>&1
(in ~/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>
if I chnage line #6 to:
<%= javascript_include_tag "default" %>
The program will run perfectly except it won't allow me to delete users (presumably because it's not running the javascript).
Environmental info:
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i386-cygwin]
$ rails -v
Rails 3.2.2
Content of ~\demo_app\app\assets\javascripts\users.js.coffee:
# 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/
Content of ~\demo_app\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 vendor/assets/javascripts of plugins, if any, 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
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
try to uncomment gem 'therubyracer' and run bundle, and also it's better to use last stable version of ruby
I searched around for other questions that discussed the gem therubyracer. I found one answer that suggested what Said Kaldybaev had suggested here. That didn't work for me. But there was another suggestiong to remove the code
//= require_tree .
from the app/assets/javascripts/application.js file.
Deleting that code made the application work (including the destroy function).
The HTML that is rendered seems right:
<img src=/assets/icons/example.png>
Inspite of the data-method and data-remote both being rendered, when I click the link, the browser seems to issue a GET because Rails complains about a lack of a route. I do want this to be a POST but I went ahead and added a GET in routes.rb and the call works but is now is a regular call rather than an AJAX call. I seem to be missing some JS file somewhere... very new to Rails 3.1 - can someone point me in the right direction?
Make sure your Gemfile has this:
gem 'jquery-rails'
and that your app/views/layouts/application.html.erb has this:
<%= stylesheet_link_tag :application %>
and that your app/assets/javascripts/application.js contains these 2 lines:
//= require jquery
//= require jquery_ujs
These parts are all needed to properly use the :remote options in Rails.