This should have been a no-brainer, but has me stumped.
For convenience, I took a bootstrap plugin (bootstrap-combobox) and turned it into a gem, so I can version it properly and all.
My gem is bootstrap-combobox-rails.
It packages up fine, bundle installs fine, but when I try to reference the assets: The stylesheet works, although I have to do it like this in my application.css.scss:
#import "bootstrap-combobox.css";
(everything else is fine without the .css).
The javascript is not found, though. No matter if I reference it as
//= require bootstrap-combobox.js
or
//= require bootstrap-combobox
I get:
$ rake assets:precompile
/Users/denishaskin/.rvm/rubies/ruby-1.9.3-p374/bin/ruby /Users/denishaskin/.rvm/gems/ruby-1.9.3-p374#oneclick/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
couldn't find file 'bootstrap-combobox.js'
(in /Users/denishaskin/clients/cs/1-click/oneclick/app/assets/javascripts/application.js:18)
Suggestions? Thanks...
Resolved this.
It was one or both of these things, I don't recall exactly which did it. Both are described here.
Making the gem into a Rails::Engine
Adding the dependency on railties into the gemspec
Related
I'm trying to push my Rails 3.2 app up to Heroku, but the push gets rejected because Sprockets can't find the directory I'm referencing with require_tree.
In app/assets/javascripts/application.js:
//= require_tree ../../../vendor/assets/extender/
The error portion of the build looks like:
Running: rake assets:precompile
rake aborted!
Sprockets::ArgumentError: require_tree argument must be a directory
(in /tmp/.../app/assets/javascripts/application.js:1)
As I understand it items under vendor/assets/ should be available as though they were under app/assets/, but I can't seem to get that to work and the way I'm doing it above works locally, so I'm running with it.
What I don't understand is why this works locally but not when pushing to Heroku. Any help is greatly appreciated!
Solved: for some reason my .gitignore was ignoring /vendor.
app/assets/javascripts and vendor/assets/javascripts get merged into the same level, so you should require_tree extender if vendor/assets/javascripts/extender/ exists.
You shouldn't go have to do ../../../vendor/assets/javascripts/. See Search Paths in http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
Rails 4.1+, so there isn't built-in support for an :assets group
I want to keep Heroku's precompile on push behaviour, but don't want the asset gems loaded by the rails server. We don't use any kind of inline coffeescript or scss template rendering in the app, only in the assets, so it's just wasted memory at runtime.
I've played around with extending the rake task, configuring sprocket-rails, and even changing application.js to application.js.erb and adding things like
//= <% require 'jquery-rails' %>
//= require 'jquery'
but still get these errors:
Sprockets::FileNotFound: couldn't find file 'jquery'
This comment from a rails issue complaining about the same problem also doesn't work for me now, and it's a couple of years old so perhaps something changed that breaks it? Or am I doing it wrong?
If I keep the asset gems in the default Gemfile group everything works fine.
The point here is to not have them loaded in the production environment, but to have
RAILS_ENV=production rake assets:precompile task
load them before it executes (and fails because of missing libraries)
I am experiencing an issue while precompiling the assets of my Rails projects.
Here is the versions of some of the gems I am using:
rails (4.2.0)
bootstrap-sass (3.3.3)
sass-rails (5.0.1)
The project is an AngularJS project sourcing the following gems from Rails Asset:
rails-assets-bootstrap-additions (0.2.3)
rails-assets-angular-bootstrap (0.11.2)
rails-assets-bootstrap-sass-official (3.3.3)
Following the README on the bootstrap-sass Github page, I renamed my app/assets/stylesheets/application.css file to application.scss and replaced its content by:
#import "bootstrap-sprockets";
#import "bootstrap";
Here is the error I get when I launch RAILS_ENV=production rake assets:precompile --trace:
** Execute assets:precompile
rake aborted!
Sass::SyntaxError: Undefined variable: "$alert-padding".
(in /home/owner/.rvm/gems/ruby-2.1.5/gems/bootstrap-sass-3.3.3/assets/stylesheets/bootstrap/_alerts.scss:10)
I looked into ClothSword's answer to this similar post, but in my case puts config.assets.precompile.inspect outputs (lambda)>, /(?:\/|\\|\A)application\.(css|js)$/], which I believe to be the default.
Would anyone have more insight on this? You can browse the source here
It looks like the problem I'm facing is that one of the gem I'm using, sprangular, is setting this precompile rule:
Rails.application.config.assets.precompile += %w( bootstrap/* )
If I comment out this rule and source my own modified version of the gem in the Gemfile, rake assets:precompile now works.
I'm not entirely sure the reason why they set a rule to precompile all of the boostrap files. Does that make sense?
I've created an issue in their Github repo to gain clarity on whether this is a bug or just me not configuring the asset pipeline properly in my app.
I will update this answer as I get clarity from the discussion over there. Feel free to make suggestions here too.
My rake assets:precompile are not working on production environment, I'm getting "Out of stack space" error
I'm running rake on Windows 7 with 8 GB, so memory is not a problem at all. This guy rake assets:precompile giving "Error: Out of stack space" error said that running on Ubuntu solved his problem, but I do not plan to do this...
After run a trace I noticed that the precompile always stopped on my application.js, here is the code:
//= require jquery
//= require jquery-ui
//= requeire jquery_ujs
//= require turbolinks
//= require calendarize
//= require_tree .
some days ago it was working, actually the only difference is the calendarize, a gem that I added. But I tried to remove it from application.js and the error continues
I'm on Rails 4 and Ruby 2 - If anyone can help it would be great! Thanks!
EDIT: I didn't had jquery-ui before to! Not using this version on gem file at least: gem "jquery-rails", "~> 2.3.0"
EDIT2: Just updated jquery-rails and added jquery-ui-rails, got the same problem. Them tried to remove everything from application.js. Same problem.
Try
rake assets:clean
and next,
rake assets:precompile
If it's not working yet try like below and trace what is the problem.
rake assets:precompile --verbose
BTW, I strongly recommend use RoR on the OSX or Ubuntu except for Windows.
There are various barriers even though you solve this problem..
Cheers, humbroll.
After research a lot, I find out that this is a Windows problem. Don't know why this happens, but I installed an ubuntu develop environment and everything works fine!
I have an application that uses redactor (a wysiwyg editor) it works perfectly locally, and it also works when I upload it, except the config file, which is located in a subfolder doesent do anything, when pushing to Heroku. I tried precompiling, using:
RAILS_ENV=production bundle exec rake assets:precompile
and
bundle exec rake assets:precompile
I have config.assets.enabled = false
The config.js file, that is not working on Heroku, is included in application.js as redactor-rails/config
What can be the problem ?
Have you added config.js to your local git repository before pushing?
[Edit]
A couple more things to check. Are you using the redactor-rails gem, and if so, is it in your gemfile?
gem 'jquery-rails'
gem 'redactor-rails'
Is your gemfile.lock checked into git?
[Edit 2]
I've now tested this out, and indeed, there's an issue with redactor-rails, which causes custom config to be overwritten by the gem's default.
On the github repo, there is a solution, which I've tested on heroku, and copied here:
rails generate redactor:config generates the file app\assets\redactor-rails\config.js.
This will not work in the asset pipeline correctly as the rake assets:precompile task
will still take config.js from the gem instead of the app (not that it'll work fine in
development though). See Overriding backend assets in production environment
The solution is to create your own config.js (or any file name) and put it anywhere in your >app's assets. Then when requiring redactor, instead of //= require redactor-rails, use:
//= require redactor-rails/redactor.min
//= require path/to/custom/config
Works for me. Hope that helps. https://github.com/SammyLin/redactor-rails/issues/16