Rails 4 asset pipeline losing vendor assets - ruby-on-rails

I can't seem to figure out how to make sprockets find assets in vendor/assets. I've ben been pushing off the problem by adding all of my assets to app/assets, but it's becoming way too cluttered.
I have read the documentation, and tried adding all of the following lines to my application.rb file.
config.assets.paths << "#{Rails.root}/vendor/assets/*"
config.assets.paths << "#{Rails.root}/vendor/assets/fonts"
config.assets.paths << "#{Rails.root}/vendor/assets/stylesheets"
config.assets.precompile << Proc.new { |path|
if path =~ /\.(eot|svg|ttf|woff)\z/
true
end
They work locally, but when I push them to the server, none of my vendor assets are there. I'm using capistrano for deployments, and I know that there were some issues with the upgrade. That could be the root of the problem, but I followed the documentation to get it deploying (almost) everything alright.

The problem turned out to be me being stupid, and quick to jump the gun on other problems. I dove too far down the rabbit hole, and lost sight of what was happening. I did not include the otf filetype in the regex, and it wasn't being included.
Facepalm
EDIT:
To clarify: all I had to do was change
if path =~ /\.(eot|svg|ttf|woff)\z/
to
if path =~ /\.(eot|svg|ttf|woff|otf)\z/

When you run rake assets:precompile are you manually setting the env to production?
The command should read:
RAILS_ENV=production rake assets:precompile

Related

asset precompile not generating any json files

I have an app which I want to deploy to Heroku. It works in development, but not when deploying to Heroku.
I am considering this to be an asset precompile issue.
But when I run bundle exec rake assets:precompile, it doesn't generate anything.
What could be the reason for this?
Seems like you overrided config.assets.precompile option and removed default values from it. Check your config/application.rb and config/initializers/assets.rb files.

Rails asset pipeline: images not looking up resource with build id

I'm getting a 404 on all of the images included with jquery-ui-rails on Rails 4.0.1 after going production. It works fine in development environment. The site is looking for /assets/jquery-ui/ui-icons_222222_256x240.png, but only public/assets/jquery-ui/ui-icons_222222_256x240-890385424135de1513f00cbecfb7f990.png exists in the filesystem. How come production build IDs are not being appended?
I've also had this problem with some fonts. For the time being I've worked around it by just manually copying and pasting to the sought path.
First thing to try is precompiling assets specifically for the production environment:
RAILS_ENV=production rake assets:precompile
If that doesn't do anything, set the following in production.rb and precompile again
config.assets.precompile += ['*.js', '*.css']
config.assets.compile = true

rails asset pipeline production precompile

I have a directory projName/vendor/assets/bootstrap/css/
I am in production mode.
production.rb contains: config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
when I run rake assets:precompile
I get
projName/public/assets/css/ but I want projName/public/assets/bootstrap/css/
I do not understand why the bootstrap directory is not there.
Actually all the top level directories under vendor/assets and app/assets are missing in public assets/
Compiled assets are written to the location specified in config.assets.prefix. By default, this is the public/assets directory.
To understand this you have to first understand what precompiling is and does. Let me explain
When you run (a rake task)
rake assets:precompile
it will create a public folder inside your application folder which will compile all your asset manifests (ie. your application.css and application.js)
How exactly does this happen ?? -> Rails comes bundled with a rake task which will compile all this. That rake task is what is shown above.
Compiled assets are written to the location specified in config.assets.prefix. By default, this is the public/assets directory.
The default matcher for compiling files includes application.js, application.css and all non-JS/CSS files (this will include all image assets automatically) from app/assets folders including your gems.
And thats exactly what that regex means (to include everything in your app/assets folder), you can also explicitly provide it as shown in the answer above.
Hope this helped.
Here are few links for your reference
http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
http://dennisreimann.de/blog/precompiling-rails-assets-for-development/
What does that regex mean? If you want to precompile everything, try this.
config.assets.precompile = ['*.js', '*.css']
Actually, if you want to precompile everything, try this:
def precompile?(path)
%w(app lib vendor).each do |asset_root|
assets_path = Rails.root.join(asset_root, 'assets').to_path
return true if path.starts_with?(assets_path)
end
false
end
# Precompile all assets under app/assets (unless they start with _)
Rails.application.config.assets.precompile << proc do |name, path|
starts_with_underscore = name.split('/').last.starts_with?('_')
unless starts_with_underscore
path = Rails.application.assets.resolve(name).to_path unless path # Rails 4 passes path; Rails 3 doesn't
precompile?(path)
end
end
(Based on the code in the Rails Guide.)

Sass / CSS files getting ignored -- Asset Pipeline issue?

So, of course I figure this out after an hour of messing with my main SASS file and wondering why I couldn't see the changes -- but it turns out that my local host isn't paying any attention to what I'm putting in my SASS files anymore.
This comes just after having switched everything over from SCSS to SASS, and I'm 100% sure the file is just getting ignored. For kicks/proof, I deleted all the styling in my application.erb.sass file (the only one with any styling any more -- I consolidated to get to the bottom of this), then saved, then restarted the server, and it's looking as styled as ever.
This seems to be an asset pipeline issue, and since I don't really know what to do with my config files, I'll paste the relevant-seeming stuff here:
config/environments/development.rb has these lines:
# Do not compress assets
config.assets.compress = false
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
# Expands the lines which load the assets
config.assets.debug = true
config/application.rb
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
# Enable the asset pipeline
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts"
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
Also, I've got "gem 'sass-rails'" in my gem file, not in any group.
Think that's all/most that's relevant. Any idea how to fix this?
run : rake assets:clean && assets:precompile
The problem seems to have been the extension on my css file (which had some embedded ruby):
erb.sass and erb.css.sass didn't work, but css.erb.sass did.
This was inexplicably stopping the file from being read, so that when I ran assets:clean/precompile, there was no css left. Before I ran that, I guess it was running my pre-compiled CSS file from before. Weird.
Apparently, these things must be compiled from the right to the left (as probably everybody but me knew), so CSS should be the type it's compiled into.
Sorry for the confusion.

Rails 3.1 assets precompile questions

Right now, every time I am changing something in the assets, I have to delete the assets folder from the public directory and then run rake assets:precompile to take effect.
Is this something right or wrong so I should put it in a capistrano task to do it automatically?
For some reason, it doesn't compile automatically the assets in production and it throws errors if I don't do the above (or it doesn't take effect the changes if there is the files already). Is there something I should put in the environments/production.rb?
Also I don't understand what the following code in the production.rb does:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
I tried false and true but I didn't understand the difference.
I'm a bit confused as at how it should work the workflow in production, if what I am doing is right and about the settings for the assets in production.
Capistrano has built-in support for precompiling assets during deployment. Just add this line to your deploy.rb file:
load "deploy/assets"

Resources