Heroku asset compile not working with Rails 3.2 application - ruby-on-rails

I feel like I have exhausted my resources trying to figure this out. I have yet to run into this error with a heroku/rails app before and am simply puzzled as to why my js/css isnt being compiled/uploaded to Heroku.
As stated in the heroku docs your options are to:
1. Compiling assets locally.
2. Compiling assets during slug compilation.
I tried the first option: ran RAILS_ENV=production bundle exec rake assets:precompile, added public/assets and saw the "Detected manifest.yml, assuming assets were compiled locally" line when deploying. No CSS.
I tried the second option (clean git checkout before assets:precompile). Added the 'config.assets.initialize_on_precompile = false' line as suggested for rails 3.x apps. And instead of seeing the expected:
Compiled jquery.js
Compiled jquery_ujs.js
Compiled application.js
Compiled application.css
etc etc
I get 'DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins!' warnings. yet that folder is completely empty
Looked into this warning with no sign of it being the root cause for this. Feels like I'm going in circles so I am hoping someone has insight. Thanks in advance!

Heroku docs suggests that add 'rails_12factor' gem to gemfile. Precompling assets before pushing to heroku is not required. And you also must use Heroku's cedar stack only.

Related

Rails 3.2 Asset Precompile is skipping files

Stack
Ruby 1.9.3
Rails 3.2.12
Issue
We have precompilation issues with our application.
We're trying to remove config.server_static_files = true and config.assets.compile = true from our production configs, but are constantly missing assets whenever we precompiled. Even though these assets live in app/assets, while other files in the same directory are seen and compiled.
Ex:
app/assets/stylesheets/application.css
app/assets/stylesheets/some_slider_lib.css
app/assets/stylesheets/bootstrap.min.css
After precompiling
public/assets/application-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.css
public/assets/some_slider_lib-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.css
And the manifest.yml is also missing the bootstrap file among other assets.
Same thing with our vendor folder.
Attempts
The following is the only way that I've managed to precompiles everything.
config.assets.precompile += ["*.css", "*.scss", "*.js", "*.coffee"]
However, this feels like overkill. I thought all files within the asset pipeline would be compiled. Is this not what is suppose to happen?
Also tried rake assets:precompile --trace, but this was unhelpful.
If anyone could provide a little guidance, suggestions or more it would be deeply appreciated.
Thanks!

Sass::SyntaxError when using Bootstrap in Rails application on Heroku

I installed twitter bootstrap by copying the files into my assets directory as per the instructions here: http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/
After following the instructions exactly as presented and executing "rake assets:precompile RAILS_ENV=development", I am able to use bootstrap 3 in my development rails server.
However, when I try to execute "heroku run rake assets:precompile RAILS_ENV=production", I get this error:
Sass::SyntaxError: Invalid CSS after "...ss","sources":[": expected "|",
was ""less/theme.les..." (in /app/app/assets/stylesheets/application.css) (sass):444
I am not sure what this means. When I open "application.css" in the assets/stylesheets folder, I can't even find a line 444. I do have some scaffold files left over after running "rails g scaffold ..." commands -- could that be causing this problem? And obviously, the deployed heroku app looks like a non-bootstrap app when I view it from the heroku page and throws a "resource not found" error.
In public/assets/application-mydigest.ccs, I found the following line of code that causes the error:
{"version":3,"file":"bootstrap-theme.css","sources":["less/theme.less","less/mixins/vendor-prefixes.less","bootstrap-theme.css","less/mixins/gradients.less","less/mixins/reset-filter.less"],"names":[],"mappings":"AAeA;;;;;;EAME,0CAAA;EC+CA,6FAAA;EACQ,qFAAA;EC5DT;AFiBC;;;;;;;;;;;;EC0CA,0DAAA;EACQ,kDAAA;EC7CT;AFqCC;;EAEE,wBAAA;EEnCH;AFwCD;EG/CI,0EAAA;EACA,qEAAA
However, it seems odd that this would only happen on production. Moreover, the CSS syntax looks fine.
This error means the assets compilation failed because of an invalid css syntax into a file you require in application.css.
In bootstrap repository there is a less directory and you can't precompile less files with rails.
If you want to use Rails and Bootstrap on a production environment I think use bootstrap-sass gem is a better option
Have you tried using rails-assets instead of the referenced method of adding Bootstrap 3? I use it on Heroku with success... and just add my own custom Bootstrap css in my normal assets folders which get loaded after the vanilla Bootstrap 3 and override it. Just add gem 'rails-assets-bootstrap' along with source 'https://rails-assets.org' to your gem file. May help diagnose if nothing else.
EIther of the two things you must take care to avoid assets compilation errors when you go live.
- Add all your assets(js/css) in manifest file(application.js/application.css)
- OR
- use assets.precompile=%w(custom.css custom.js) directive to handle them explicitly
because when u precompile...rails copies everyting(images/fonts) except js/css into public folder to be taken care by the server(apache),hence the setting # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false in production.rb during assets precompile fallback is disabled by default in production/staging as Rails assumes it will be handled by webserver.Hence we have manifest file to define our assets which gets precompiled during assets:precompile and verified by looking for public/assets/javascripts/application.css/js after compilation which gets created requiring all files mentioned in app/assets/stylesheets/application.css and app/assets/javascripts/application.js after running assets:precompile...so hope u know where you missed.
FOR MORE DETAILS..REFER this

When does Rails compile application.css?

I have a Rails app where I replaced a xxx.cs.scss file in assets/stylesheets/.
I restart Rails on my Mac using $ rails s.
And the old xxx.cs.scss is still in the application.css file according to my browser.
Why wouldn't the application.css file get re-compiled?
Thanks for the help!
Double check the asset compilation options in your environments/development.rb file to see if compilation is turned off.
Also, if you previously pre-compiled your assets (via rake assets:precompile) the compiled assets will take precedence over the on-demand compiled assets in your development environment. You may want to do rake assets:clean to get rid of any pre-compiled assets, then restart your local Rails server, and try again.

Precompiling Assets Failure During Deployment

I am using Capistrano to precompile my assets during deployment, and I am getting an error that isn't very useful to me.
* executing "cd -- path/to/releases/20130507161214 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
*** rake aborted!
*** wrong argument type nil (expected Data)
*** (in /path/to/app/assets/javascripts/application.js)
*** /path/to/gems/therubyracer-0.11.4/lib/v8/context.rb:67: in 'New'
Here is my application.js that is referred:
//= require jquery
//= require jquery_ujs
//= require bootstrap
Update
So I tried to just remove application.js entirely and run it again, but then it complained about another js file of mine (but the same non-helpful error). Then I removed all of my js files and it started to complain about my css files.
If all js and css files are removed, the precompile does succeed (but obviously without my needed js and css files).
I am using .js.coffee and .css.scss for all of my non-image assets.
Update
#TomDavies answer did indeed help me, but still having the issue. During deployment, it was just failing on precompile and not giving me information. So I did what Tom mentioned, I precompiled on my development machine, but in the production environment, and noticed I was also having issues.
The error it gave me was "Unexpected INDENT", but it would not tell me a line number, just a file name...
I eventually discovered I was missing a comma in my ajax request. Apparently it works without it in the development environment, just doesn't precompile without it...
Here is what I had:
$.ajax 'some/url'
success:
alert 'yay!'
Here is what I needed:
$.ajax 'some/url',
success:
alert 'yay!'
Notice the comma at the end of the top line... now precompiles great in development. I thought for sure that fixing the errors during precompile on the development machine (but production environment) would fix the deployment issue, but to no avail. It is still failing with the same error at the top wrong argument type nil (expected Data).
tl;dr
I am able to run the rake assets:precompile RAILS_ENV=production on my development machine, doesn't work on the production machine, gives the error at the top. Not sure how to debug this one.
This looks like a possible gem problem, since it's failing on the application.js file and your content looks correct. Which version of Ruby are you working with? If you have switched different versions, you may want to clear out your gems directory and reinstall them from scratch. I have experienced issues with gems installed under one Ruby version leaving fodder behind that causes strange things to happen under another version.
Your file should be called application.scss if you want to import other scss from it.
I'm not sure of you exact error, but for asset pipeline issues you should always try compiling them locally in development. The errors are usually much more obvious that way and you can trial / error more easily. Here are some steps I usually leave in my config/environments/development.rb for getting asset precompilation to work locally:
# NOTE: To test asset pipeline in dev uncomment the following configs and run:
#
# $ RAILS_ENV=development rake assets:precompile
#
# It is recommended you rm -rf public/assets when you are finished or this may affect
# your local dev environment
#
# config.assets.compress = true
# config.assets.compile = false
# config.assets.digest = true
And here is a gist of the same:
https://gist.github.com/atomgiant/5438672
I would also look to using Node.js as the ExecJS runtime. There are several documented issues with TheRubyRacer and memory management (https://github.com/cowboyd/therubyracer/issues/350) and it seems that the project has been abandoned (https://github.com/cowboyd/therubyracer/pull/348).
Assuming you have the latest Node.js installed, you can prepend/append EXECJS_RUNTIME="Node" to your precompile task:
rake assets:precompile RAILS_ENV=production EXECJS_RUNTIME="Node"
As a bonus, this sped up asset compilation by an order of magnitude.

Rails precompile - all.js missing

I am new to rails and using version 3.1.0 and trying to deploy to heroku. I have a very simple application that i have managed to get up and running on heroku after working my way through several issues. I used the command
bundle exec rake assets:precompile
to get heroku to load the assets for the application (i read that heroku requires this for version 3.1.0). The problem is that when i try to run the application, the server gives the error
ActionController::RoutingError (No route matches [GET] "/assets/all.js"):
i have all of the required javascript files in public/javscripts but i cannot find any version of all.js in the assets directory. I have included
config.assets.precompile << '*.js'
in config/application.rb but to no avail.
I was wondering if someone could tell me how I get the precompile to create all.js in the assets directory or if I am completely off track here. i was under the impression that the precompile function compiled all of the javascript files into a single optimized file.
Also, if anyone has any good links for a beginner to understand how the precompile functionality works in rails I would be very appreciative.
Thanks in advance.
The best guide is the official rails guide. There is also the Railscast about it.
In a nutshell your Javascript files go in app/assets/javascript from where the precompile task will process them and put then in the public/assets directory. You should not have to change the precompile config option if the follow the defaults. Don't forget to the use the correct helpers to reference your files.
Read the resources above, and if you are converting an existing app watch the Railscast and follow the last section of the guide - these should point you in the right direction.

Resources