I'm using rails 3.2, but I'm compiling my coffee files with CodeKit.
I still want my coffee files to live inside 'assets', but each time I restart rails, it finds them in there and tries to compile them itself.
My files live in /assets/cafe/myscript.coffee, and codekit compiles them into /assets/javascripts/myscript.js
The coffee-rails gem is already commented out in my gemfile (when rails tries to (re) compile it it gives "throw Error("LoadError: no such file to load -- coffee_script)" - though I really dont want it to even try compiling.
Setting "config.assets.compile = false" in application.rb results in "application.js isn't precompiled"
you should probably just configure your sprockets manifest to not require the whole tree.
edit app/assets/javascripts/application.js
typically it looks like this:
//= require jquery
//= require jquery_ujs
//= require_tree .
change that to
//= require jquery
//= require jquery_ujs
//= require myscript
An (inferior) workaround is to put my coffeescripts inside "App" rather than "assets" (so one more branch up the tree.)
This sucks because it's not where they should go, but at least it does put it outside rails' stalker-tendencies to find coffeescript files anywhere in assets and try to compile them.
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'm following this tutorial: https://thinkster.io/angulartutorial/angular-rails/ and everything went well till the part where I had to arrange my angular code with folders in the rails assets pipeline javascripts and use the gem 'angular-rails-template' (https://github.com/pitr/angular-rails-templates) to reach them.
I've installed the gem through the Gemfile and I'm getting a "couldn't find file 'angular-rails-templates'" error even though I've required the file in the application.js:
//= require angular
//= require angular-rails-templates
//= require angular-ui-router
//= require_tree .
Any suggestions?
Apperantly I was sure that I restarted the server, which I didn't. If anyone encouter this problem try the old fashioned solution to fix it.
In my application.js file, I have the following:
//= require jquery
//= require vendor
When I load up a Rails server with rails s the application.js file that is served still has the require statements at the top. I expect it to remove these lines and load the jquery file separately.
I'm using Rails 3.2.19. My RAILS_ENV is not set.
Though I'm not entirely sure that what you're doing doesn't work, I typically use //= require [name of js file]. e.g. //= require bootstrap.js when bootstrap.js is inside the vendors/javascript folder.
Are you using an old version of Ruby? Maybe something from before 1.9.3? I had similar before problems when upgrading Rails without upgrading Ruby.
Bug with sprockets 2.2.1
Updated to sprockets 2.2.2 (via bundle update sprockets) and it now works
I just installed the rails-backbone gem and then rails g backbone:install.
I see a list of javascript references to backbone on application.js but it does not copy them to the project and I'm not sure if this is normal.
//= require backbone
//= require backbone_rails_sync
//= require backbone_datalink
//= require backbone/myapp
If this is normal, where is it possible to find backbone_rails_sync and backbone_datalink. I'm afraid that by simple searching will maybe not find the same version tested for this gem?
These files are inside the gem and served through Rails Asset Pipeline.
You could find them in the gem souce.