Currently working on the Ruby on Rails tutorial (railstutorial.org) and in Chap 8. you make a dropdown menu using bootstrap classes for signed in users.
To make this work the book says to include
//= require jquery
//= require jquery_ujs
//= require bootstrap
in your application.js file.
This does not work locally or on heroku.
However:
//= require bootstrap
//= require jquery
//= require jquery_ujs
works locally, not on heroku. This also creates a ton of error messages in the console (Uncaught TypeError: cannot read property 'fn' of undefined)
Every stack thread and googled page I go to says that bootstrap goes first in local and jquery first in production. Meanwile I'm pulling my hair out.
git hub: https://github.com/nelsonkhan/sample_app
heroku: https://guarded-shelf-3017.herokuapp.com/
you need to have all 4 of these:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
Make sure your assets are properly compiled when you deploy on heroku. Check here for more details: https://devcenter.heroku.com/articles/rails-asset-pipeline
Changing production.rb helped for me
config.assets.compile = true
Related
I'm tryin to solve this for nearly 2 days. I'm pretty mad at now.
I'm using Spree (latest version) with Rails 5. I'm trying to use W3's Shape template as theme. Css is ok and working fine but I can't manage to get workin javascript assets.
Here is my vendor/javascripts/spree/frontend/all.js
//= require jquery
//= require jquery_ujs
//= require accounting.min
//= require shape/all ---> As you can see i require my template's assets
//= require_tree .
//= require spree/frontend/spree_auth
//= require spree/frontend/spree_i18n
And here is the assets/javascripts/shape/all.js
//= require_tree .
And inside that Shape folder, there are javascript assets.
When in development mode, everything works perfect. There is no issue. But when i try to switch production mode or deploy to heroku, template's javascript assets does not included.
Thank you all.
Edit: For a temporary solution, I did include my problematic js assets by old classic html way. But still I'm really curios about how can this happen.
This is my application.js:
//= require jquery
//= require jquery_ujs
//= require_tree .
//= stub subscriptions
It has always worked as expected and subscription.js is another file which is compiled separately.
If I add this line at the top of subscriptions.js:
//= require jquery
The subscriptions.js is compiled as expected and includes jQuery, but jQuery disappears from application.js: in the browser console I get errors like
ReferenceError: jQuery is not defined.
I cannot find a way to have jquery compiled/included in both the manifest files.
I use a development environment with Rails 4.2.4 + Puma and the default jquery-rails gem.
It's the expected behavior of the stub directive: not only subscriptions but also all its dependencies will be stubbed.
The only solution is to avoid using require_tree and stub.
I got this application.js
And when I run my app locally with env production dropdowns work fine. But after deploy to a real server they stopped working.
//= require ckeditor/init
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require jquery.turbolinks
//= require turbolinks
//= require_tree .
How can I fix this?
up1
Uncaught TypeError: Cannot read property 'langEntries' of nullapplication-c6f1be54480428c9ab047aa15b1a5d07.js:4
window.CKEDITOR.window.CKEDITOR.dom.CKEDITOR.plugins.setLangapplication-c6f1be54480428c9ab047aa15b1a5d07.js:21 (anonymous function)
up2
I dev env I have a lot of errors
UP3
When I move ckeditor directory to public there're no errors.
I was having a similar issue and tried many of the answers found here untill it worked. I suggest deleting the public and tmp folders (or their content) and deploying like that, then precompile the assets in your server. That and fiddling with the order of the requires worked for me. Hope it helps.
I tried a lot of things but ended up removing turbolinks completely.
I am following Ruby on Rails Tutorial (3.2) by Michael Hartl. In chapter 9 delete user by admin user functionality is introduced. This is working fine on my local machine but not on heroku. Though the generated HTML is same both locally and on heroku
delete
When I click delete link locally I get popup with you sure? and on clicking OK it deletes the user. However with same code on heroku when I click delete link, it takes me to user page of that user instead of pop up with you sure? message.
Can someone please guide?
My application.js had following entries
//= require jquery_ujs
//= require bootstrap
//= require jquery
//= require_tree .
I tried to change the order as below with no success
//= require bootstrap
//= require jquery
//= require jquery_ujs
//= require_tree .
Try to precompile the static assets. In your local console type:
rake assets:precompile
Then push the changes up to heroku
$ git add .
$ git commit -m "Add precompiled assets for Heroku"
$ git push heroku master
I had done assets:precompile already so that was not the issue. However I have found the solution (rather a workaround)
Unfortunately same application.js does not work on both my local setup and on heroku. Following order works on heroku
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
Where as following order works on my local setup otherwise I run in to issue described in thread twitter bootstrap drop down suddenly not working
//= require jquery_ujs
//= require bootstrap
//= require jquery
//= require_tree .
I've made all this steps to clear/precompile the source and many others, none of them worked for me.
To resume, what I nedded to do was change the "Compress JavaScripts and CSS." on the file "config/environments/production.rd" that was using uglifier to use sass.
config.assets.css_compressor = :sass
Tip: Changing the local server to run as "production", helps to reproduce the problem localy.
rails server -e production
For some reason my bootstrap broke after I precompiled my code. This started because I couldn't push to heroku because of a precompile error.
So here are the contents of my application.js file:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap3
//= require bootstrap
//= require bootstrap/dropdown
//= require_tree .
Maybe the order is wrong? I just added .../dropdown hoping it would help, but it did not. I just realized I can actually remove both bootstrap lines without affecting my resulting site.
For my gems, I have:
gem 'bootstrap-sass', "~>3.0.3.0"
...
gem 'bootstrap-will_paginate', '0.0.6'
Here is a link to my other question, which is similar but less focused: Ruby on Rails: Ran rake assets:precompile and now both local and heroku deployment don't include bootstrap
Any help would be greatly appreciated. I'm getting pretty frustrated, it's been several days of failed action.