How uncommenting jquery results in working of rails server? - javascript

I created a new rails controller $ bin/rails generate controller welcome index
Modified my View Hello, Rails!
when I restarted my rails server, I faced the below issue.
Sprockets::FileNotFound in Welcome#index
Showing /home/venkata/Downloads/app/app/views/layouts/application.html.erb where line #5 raised:
couldn't find file 'jquery' with type 'application/javascript'
Checked in these paths:
/home/venkata/Downloads/app/app/assets/images
/home/venkata/Downloads/app/app/assets/javascripts
/home/venkata/Downloads/app/app/assets/stylesheets
/home/venkata/Downloads/app/vendor/assets/javascripts
/home/venkata/Downloads/app/vendor/assets/stylesheets
Extracted source (around line #13):
11
12
13
14
15
16
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Rails.root: /home/venkata/Downloads/app
Now when I uncomment the =require jquery in app/assets/javascripts and restarted the server, got the expected output. wondering How this happens by uncommenting that particular line?

// is a comment but //= is not, //= require jquery includes the jquery library.
More info here - https://guides.rubyonrails.org/asset_pipeline.html#search-paths

Related

JQuery is not loading initially since code base was moved

Browser : Chrome/IE
Rails -> '6.0.4.4'
JQuery Gems ->
gem 'jquery-rails', '4.4.0'
gem "jquery-ui-rails"
gem 'jquery-modal-rails-assets'
Deployment: Capistrano
Application.js contents ->
//= require jquery
//= require jquery_ujs
//= require js/bootstrap.min
//= require js/ekko-lightbox.min
//= require jquery.placeholder
//= require jquery-ui
My application was working perfectly fine till I moved the code to a different version control system. All I needed to change for deployment is an entry in the config/deploy.rb to point to the new repo url. There was no other code change.
The deployment was successful but since then, when the application first loads, the UI does not seem to load JQuery.
I keep getting this error on UI -> Uncaught ReferenceError: $ is not defined
I ran this test to see if JQuery loads and it does not.
$(document). ready()
Uncaught TypeError: Cannot read properties of undefined (reading 'ready')
After several clicks, it eventually loads JQuery. I am not certain what is causing it or what I can I do to correct it?

RoR: Highcharts boost.js not loading

I've several graphs with an huge amount of data, which is pretty slow. So I decided to use Highcharts own solution: boost.js.
My application.js file loads all additional JS-files, inclusive the boost.js. I've read that the boost-file needs to be loaded after the Highcharts file itself.
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require ./vendor/highcharts
//= require ./vendor/boost
//= require ./vendor/moment
//= require_tree ./vendor/
//= require_tree ./source/
Then I've precompiled the whole assets:
rake assets:precompile RAILS_ENV=development
After that I restarted the server. But unfortunately it's not possible to load the boost-file.
Error-Message:
ActionController::RoutingError (No route matches [GET] "/assets/boost.js.map"):
Following versions are included:
Rails: 5.2.4.1
Highcharts: 8.0
Ruby: 2.5.1
Does anyone know what I'm doing wrong?

Rails can't require a javascript file that exists in the same folder

Just deployed a Rails 5.x application and installed a theme. The theme's contents are located within the app/assets/javascripts/theme-js and app/assets/stylesheets/theme-files folders.
Inside of the app/assets/javascripts/application.js file includes the following:
//= require jquery
//= require jquery_ujs
//= require_tree .
// Required for the SmartAdmin theme
//= require theme-js/app.config.js.erb
//= require theme-js/app.js
And inside of the app/assets/javascripts/theme-js folder are have the following files (included with the theme):
app.config.js.erb
app.js
application.js
The problem that I'm having is that inside of the application.js file contains a line that states: //= require app.config, but Rails generates me an error stating the following:
couldn't find file 'app.config' with type 'application/javascript'
Even though app.config.js.erb is in the same folder as application.js. Is there any reason why this would happen? Can't figure out why this won't work. I've even tried //= require app.config.js and //= require app.config.js.erb and neither one of them work.
I noticed that //= require ./app.config appears to work whereas //= require app,config doesn't. Something new with Rails 5.x perhaps? I'd have to modify all of the require statements to fit this unless I'm missing something.
Problem solved. Just needed to add the custom theme-js and theme-css folder to the assets pipeline so that Rails can search those folders for the appropriate files when using //= require <file>. Assuming this is what I needed to do, although I'm not sure if it's best practice.

rails: assets js manifest not picking up specific js file

I can't get my prints.js file to get picked up by the manifest (I presume that is the issue.)
this is in the appliction.js manifest:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require 'main'
//= require 'cards'
//= require 'prints'
//= require_tree .
the cards.js has a console log saying hello like this :
$(document).on('turbolinks:load', function() {
console.log('cards js file executed.')
...
});
When I do the same thing for cards.js like this:
$(document).on('turbolinks:load', function() {
console.log('Prints js file executed.');
});
the console only calls out the cards.js console log statement, but not prints.
I restarted rails server, and rebooted my local machine hoping that would pick it up. but no result.
(Rails 4.2)
EDIT
I am decided to use the application.js for hosting the function I need.
Though it works, it feels 'cheap' and if anybody has any suggestions of what could make a manifest not include files, that would be greatly appreciated. But I have a temporary solution.
try without quote like following. after change please restart server
//= require main
//= require cards
//= require prints

RoR 4.2.0 Jquery not defined

in my ror application i've a jquery error during the execution. On the Google Chrome Application appear this message
Uncaught ReferenceError: jQuery is not defined
this is my 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
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require turbolinks
//= require_tree .
$(function(){
$(document).foundation('alert');
});
In the gemfile is present the jquery-rails gem.
I really don't know where crush my head. All the help is appreciated
remove Gemfile.lock
do
$bundle install
now check if jQuery works

Categories

Resources