This is the error generated whenever I try to do a simple page reload:
Completed 500 Internal Server Error in 129ms
** [Raven] couldn't find file 'turbolinks'
(in /hj-project/app/assets/javascripts/comfortable_mexican_sofa/admin/application.js.coffee:2) excluded from capture due to environment or should_capture callback
ActionView::Template::Error (couldn't find file 'turbolinks'
(in /hj-project/app/assets/javascripts/comfortable_mexican_sofa/admin/application.js.coffee:2)):
6: = stylesheet_link_tag 'comfortable_mexican_sofa/application'
7: = stylesheet_link_tag 'comfortable_mexican_sofa/admin/application'
8: = javascript_include_tag 'comfortable_mexican_sofa/application'
9: = javascript_include_tag 'comfortable_mexican_sofa/admin/application'
10:
11: = yield :head
12: = cms_hook :html_head
sprockets (2.2.3) lib/sprockets/context.rb:102:in `resolve'
sprockets (2.2.3) lib/sprockets/context.rb:142:in `require_asset'
Here is the app/assets/javascripts/comfortable_mexican_sofa/admin/application.js.coffee file:
//= require turbolinks
//= require tinymce
//= require cocoon
//= require jquery.address
//= require_self
//= require_tree .
window.CMS.wysiwyg = ->
tinymce.init
selector: 'textarea[data-rich-text]',
plugins: 'advlist autolink lists link image preview hr anchor pagebreak searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime nonbreaking save table contextmenu directionality paste textcolor',
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | image uploadimage",
image_advtab: true,
From the Gemfile.lock:
comfortable_mexican_sofa (1.8.5)
turbolinks (5.2.0)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
DEPENDENCIES
comfortable_mexican_sofa (~> 1.8, >= 1.8.5)
turbolinks (~> 5.2.0)
Rails 3.2.
What could be causing this?
It seems the issue was the version of Turbolinks I was using.
Turbolinks 5 doesn't seem to work with Rails 3.2.
So once I did this in my Gemfile:
gem 'turbolinks', '~> 2.5', '>= 2.5.3'
And then did a bundle install and/or bundle update it works like a charm now.
Related
I'm upgrading a rails app from 4.2 to 5.0. The ruby version is 2.6.4
The app has a view that allows the user to click a link to run a scheduling script that assigns students into courses/classes. The script can take several minutes to run to completion, so we show a modal dialog box that, like a progress-bar, shows where the process is currently at. But in the rails 5.0 version, this is not working. There is no error(s), just the popup is not appearing. I figured it was a JQuery thing, so using try/catch blocks, I found it is in the .dialog(...) call. But I'm not sure why it is failing. I believe I have the correct JQuery gems and the assets/files set up correctly for rails 5.0.
Gemfile:
source 'http://rubygems.org'
gem 'rails', '~> 5.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
...
Gemfile.lock:
...
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
...
app/assets/application.js:
...
//= require jquery-ui
//= require jquery
//= require jquery_ujs
//= require jquery-ui/widgets/dialog
//= require_tree .
app/assets/stylesheets/application.css
...
*= require_self
*= require_tree .
*= require jquery-ui
*= require jquery-ui/dialog
The popup form:
app/views/elements/_scheduling_dialog_popup.html.erb:
<%
# This partial will attach a Jquery event to a submit button that will display a modal-screen
# during the (potentially) long scheduling process.
%>
<% content_for :head do %>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("a#autoschedule").click(function() {
JQuery('div#import_modal_box').dialog({bgiframe: true, modal: true, width:450, draggable: false, closeOnEscape: false, resizable: false});
});
});
</script>
<% end %>
<div id="import_modal_box" style="display:none;">
<p style="float:left;margin-right:1em;"><%= image_tag 'ajax-loader.gif' %></p>
<h3>Auto Class Assignment for <%= pluralize(Student.count,'student') %></h3>
<p>There are <%= pluralize(ClassTime.sum(:enrollment_limit),'spot') %> available in <%= pluralize(ClassTime.count,'class') %> for <%= pluralize(UpcomingCourse.count,'course')%>.</p><p>This may take a few minutes, please wait.</p>
<p> </p>
</div>
I've read through the docs at: ruby-docs. I see I only need to use //= require jquery-ui to require everything , but I added the //= require jquery-ui/widgets/dialog just to be sure.
What am I missing to get this to work?
Thanks for any advise.
I was "finally" able to resolve this issue. It actually had nothing to do with the dialog() function, directly. I brought up the Developer Tools and ran the Console tab/window to see if I was getting any errors or warnings and found I had a ton of ReferenceError: jQuery is not defined .... errors. After some searching I found that Rails 5.2 does not need jquery_ujs, so I removed the //= require jquery_ujs line from my assets/javascripts/application.js file. Now it works.
I have a fresh rails project where I only generated a controller. I've followed the directions to install bootstrap according to the bootstrap gem, and I keep getting the following error:
ActionView::Template::Error (identifier '(function(opts, pluginOpts) {return eva
l(process' undefined):
5: <%= csrf_meta_tags %>
6: <%= csp_meta_tag %>
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbol
inks-track': 'reload' %>
9: <%= javascript_include_tag 'application', 'data-turbolinks-track': '
reload' %>
10: </head>
11:
(execjs):1
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html
_erb__511219785_80461480'
I've followed all the instructions according to this webpage: https://github.com/twbs/bootstrap-rubygem
My code:
# Gemfile
gem 'bootstrap', '~> 4.1.1'
gem 'jquery-rails'
# app/assets/javascripts/application.js
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require jquery3
//= require popper
//= require bootstrap
//= require_tree .
# app/assets/stylesheets/application.scss
#import "bootstrap";
Note, I also did remove *= require and *= require_tree from the application.scss and I did make sure that it's a scss file and not a css file.
This seems to be a current issue with ExecJS and duktape on Windows.
See the following link for more information: https://github.com/twbs/bootstrap-rubygem/issues/157
In short, to resolve this issue you can simply remove/comment out duktape from your Gemfile. If you're going for Node.js as your JS runtime, remember to actually install it (Node.js).
If you still have problems, remove all //= require directives from your application.scss and keep those in application.js instead.
application.js
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
//= require jquery3
//= require popper
//= require bootstrap-sprockets
application.scss
#import "bootstrap";
Gemfile
Remove gem 'duktape'
gem 'autoprefixer-rails'
gem 'bootstrap', '~> 4.1.1'
gem 'jquery-rails'
From a comment on the issue:
duktape has become the default JS Runtime in Windows sometime ago in
rails/rails#30014.
If you look into other similar issues involving Exejs you might found
out that duktape is actually the culprit (however its execjs here for
definition of duktape context). If you change your runtime environment
to use Nodejs, the error would be resolved, as the case with
#yasunari89
In config/boot.rb ENV['EXECJS_RUNTIME'] = 'Node'
You can find more info in #152 , #153 and #155 . However, above issues
with invalid regex was fixed with new version of duktape, for more
info visit judofyr/duktape.rb#41 The new version which resolved the
invalid regex issue , started causing issue which you are encountering
now. This issue happens because ( as defined in execjs) duktape
doesn't support complex contexts and full JS as identifier.
However a PR is under review that will possibly resolve the issue,
thanks to #judofyr
You should also make sure that your application.html.erb is setup correctly. Here is an example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>title</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<div class="container">
<%= yield %>
</div>
</body>
</html>
ExecJS supports several runtimes, not just duktape and NodeJS.
https://github.com/rails/execjs
ExecJS supports these runtimes:
therubyracer - Google V8 embedded within Ruby
therubyrhino - Mozilla Rhino embedded within JRuby
Duktape.rb - Duktape JavaScript interpreter
Node.js
Apple JavaScriptCore - Included with Mac OS X
Microsoft Windows Script Host (JScript)
Google V8
mini_racer - Google V8 embedded within Ruby
I am following screencast about twitter bootstrap basics to try to understand bootstrap more, but for some reason when I go to localhost, my app has no styling.
I have tried the steps from github repo https://github.com/seyhunak/twitter-bootstrap-rails as well.
I have also followed instruction from this SO post, but when I added the line *= require bootstrap_and_overrides, it shows FileNotFound error.
Here is what I did, after Rails new app bootstrap_practice:
rails g scaffold Product name price:decimal --skip-stylesheets
rake db:migrate
# added gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' on gemfile (I have also tried just gem 'twitter-bootstrap-rails'
bundle install
rails g bootstrap:install
I checked assets and it has the necessary assets.
Stylesheets (application.css)
*
*= require_tree .
*= require_self
*/
JS:
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .
Lastly, my application.html.erb has
<%= csrf_meta_tags %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
I am pretty sure that is everything needed. Why is my application on localhost not styled?
So, I've used twitter-bootstrap a lot of ways in Rails, and my favorite is with the bh gem. Bootstrap Helpers on github.
# Gemfile
gem 'bh'
# application.html.erb
<%= stylesheet_link_tag bootstrap_css %>
<%= stylesheet_link_tag font_awesome_css %>
<%= javascript_include_tag bootstrap_js %>
All the assets are delivered through the CDN.
An official SASS repo was released since the railscasts was released. (Rails comes with SASS out the box.)
https://github.com/twbs/bootstrap-sass
The repo by seyhunak is maintained in LESS, which requires therubyracer too.
I cannot get CoffeeScript working with Rails. This is the first time I'm using CoffeeScript and I'm also fairly new with Rails too, so I don't know how to make this simple CoffeeScript function to work in the right way. Below is my people.js.coffee file at app/assets/javascript directory.
myFunction = ->
alert "test"
The alert “test” message only shows up when I load the page (app/views/people.html.erb and _form.html.erb partial); not when I click the below button in the form:
<%= submit_tag "Test CoffeeScript", :type => 'button',
:id => 'coffeeScript', :onclick => 'myFunction()' %>
I don't know why this strange behaviour is happening. Why :onclick is not working? The generated source code for the button should be ok:
<input id="coffeeScript" name="commit" onclick="myFunction()"
type="button" value="Test CoffeeScript" />
Below is my application.js file at app/assets/javascript.
...
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
My Ruby version is 2.1.0
Here are some values when I ran bundle show command:
coffee-rails (4.0.1)
coffee-script (2.2.0)
coffee-script-source (1.7.0)
jbuilder (1.5.3)
jquery-rails (3.1.0)
rails (4.0.2)
railties (4.0.2)
sass (3.2.19)
sass-rails (4.0.3)
sprockets (2.11.0)
sprockets-rails (2.0.1)
turbolinks (2.2.2)
My JavaScript files are working ok; I tried similar type of function in JavaScript and it was ok.
It's because the function is in another scope. You can do it either with unobtrusive jquery.
$ ->
myFunction = ->
alert("test")
$("#coffeeScript").on "click", ->
myFunction()
And remove the onclick handler from
<%= submit_tag "Test CoffeeScript", type: 'button', id: 'coffeeScript' %>
or...
root = exports ? this
root.myFunction = () -> alert("test!")
I'd recommend the first one, but that is just my opinion though. Also, you have to be very careful about indentation in CoffeeScript, it works a lot like Python, whitespace matters.
An explanation on scopes and js/coffee is here How do I define global variables in CoffeeScript?
I want to use bootstrap in my project. My operating system is Windows, Ruby version is 1.9.3, Rails version 4.0.4.
I try to bundle one gem every time because there is dependence in some gem when I execute bundle install.
bootstrap-sass (2.3.2.0)
sass (3.3.5, 3.2.19)
sass-rails (4.0.2)
sprockets (2.12.0, 2.11.0)
Now, I add //= require bootstrap into application.js and add #import "bootstrap" into application.css.scss. But when I start server, I got Load Error in *Controller#home:
cannot load such file -- sass (in D:/first_app/app/assets/style sheets / application.css.scss
Extracted source (around line #5):
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
Rails.root: D:/rails_projects/first_app
Any advice?
Did you make sure that you also removed the sprockets //= require directive in your application.css.scss file?
Also, make sure all your gem versions are aligned. According to this rubygems page, version 2.3.2 of boostrap-rails requires version 3.1 for the saas gem. Running bundle install should also notify you of any gem version mismatches in your Gemfile.
Finally, if you're using Rails 4, why are you using an older version of bootstrap-rails? The latest stable version of bootstrap-rails is 3.1.1.0 (as of Feb 13, 2014).