Heroku can't find some of my rails assets - ruby-on-rails

I'm new to web development, and I've been working on a simple app for learning purposes. I've been able to deploy to Heroku from my local machine, but for some reason, the custom classes that I use for some vector images aren't rendering on Heroku.
This is my page, and as you can see, there are just squares where there should be different images. Looking in the inspector, you see the following errors:
Failed to load resource: the server responded with a status of 404 (Not Found) - https://enigmatic-hollows-2702.herokuapp.com/assets/flaticon.woff
Failed to load resource: the server responded with a status of 404 (Not Found) https://enigmatic-hollows-2702.herokuapp.com/assets/flaticon.ttf
I have tried recompiling assets, recommitting, and pushing to Heroku, but this error persists. What's weird is that if I use Heroku Bash and view the Heroku file directory, it looks like the files are there:
But they are still throwing up that error in the inspector. I've also got the following set in my production.rb file:
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.js_compressor = :uglifier
Any idea what could be causing this asset issue? I'm using Rails 4.2.0.

I was able to answer my own question after reading through this link. Essentially, I moved the font files out of my CSS directory and into their own fonts directory under the app/assets directory, and then in production.rb added the following line to the Application class:
config.assets.paths << Rails.root.join("app", "assets", "fonts")
and presto! It worked. I didn't mess around with #font-face in CSS, since the assets I'm using from flat-icons are built through custom classes used in span or div blocks.

Related

Assets not rendering in production rails

I have precompiled the assets in production but the application is not able to load the assets. My app is deployed on AWS EC2
I checked in the server in public/assets folder the application.css is present.
but still it says 404 error.
My production.rb configuration is
My nginx.conf settings are:
The 404 is based on that line in your config: config.serve_static_files = true. That might be the wrong name depending on your rails version. I believe that setting is named config.serve_static_assets in Rails prior to version 5.
If you don't have a server (nginx/etc) then you want that setting to be true. Otherwise you need to reconfigure your server to point at your /public directory, and make sure rake assets:precompile runs successfully.
I had the same problem
set config.assets.compile = True
It works for me.
The problem was my configuration in nginx of root path was wrong. so assets were not pointing to wrong path.
I changed in nginx.conf:
from root /home/deploy/appname/public
to root /home/deploy/appname/current/public
AND in production.rb
config.serve_static_assets = true to config.serve_static_assets = false
I did the same as you:
root /home/deploy/appname/public root => /home/deploy/appname/current/public
And that works for me. With the unique difference that i left the config/production.rb file like this:
config.public_file_server.enabled = true
config.assets.compile = true
I'm using Rails 5.

Running assets precompile in Rails 4.2.5 locally creates problems with "production.rb" defaults

I've built an experimental website using Rails ver. 4.2.5.1, on a CentOS 6.6 Linux box. I followed the "Getting Started With Rails" guide, and the Weblog build tutorial,
and then made changes to use SSL, and run in production mode.
To precompile the assets (javascript and images), I ran "rake assets:clobber" to remove previous cached results, and then "rake assets:precompile". This creates the "fingerprinted" filenames (long hex string (MD5 hash?) catenated to original filenames), and drops compiled assets into ../Weblog/public/assets directory.
The "assets:precompile" process is documented in the Rails "Asset Pipeline" documentation, and the Sprockets documentation.
The documentation I followed is at:
http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
https://github.com/rails/sprockets-rails
The "production.rb" file as generated by default using the methods in the "Getting Started With Rails" guide, does not seem to work. I start the WEBrick rails server using a two line script file, which is:
export SSL=true
rails server -b 0.0.0.0 -p 3000 -e production
I wanted to use the assets:precompile feature, and to make this work, I have made changes to the "config/application.rb" file, as per the sprockets-rails documentation, and included the line:
require 'sprockets/railtie'
I also had to made modifications to file "config/environments/production.rb" file. The default version of the file had:
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
Note that the :uglifier line was active, but the :sass line was commented out.
The default production.rb file also had this line:
# Do not fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
What I had to do to make the WEBrick server actually operate with precompile assets, in production mode, from the Linux box, was to invoke the css_compessor, and to comment out the "config.assets.compile = false" line, not toggle it. (If the assets are already locally precompiled, then I don't need or want to compile them live, I am assuming)
The changes to the config/production.rb file to make the production mode webserver operate on the CentOS box, are thus:
# Compress JavaScripts and CSS.
# config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed
# config.assets.compile = false
And that seems to do it. Without these changes, images would not render in the browser (Firefox 44 on Windows/ Safari on iOS/ Firefox on Android 5.1.1), and the "Destroy" link (to invoke delete method and delete an article from the database of articles) would not bring up the confirmation dialog box, or do the delete action. With the above changes to production.rb it all works, so when I run the server, the image files display, and the javascript to actually run the "Destroy/delete" process is getting served up to the browser, and the tutorial Weblog website works as expected. But it won't work if "config.assets.js_compressor = :uglifier" is turned on (by removing the # comment), and it won't work if the "config.assets.compile = false" is not commented out.
As near as I can tell, the precompile is working, and the precompiled assets, with the fingerprinted info (the long MD5 hex string) added to the filenames of the image files, are being served correctly, as is the javascript.
I understand most deployments are to Heroku and AWS, so my use of my own hardware for production mode is a bit non-standard for Rails with WEBrick, but I am curious as to why. Am I missing some needed step?
Is there a different (better?) way to do the assets precompile assuming production mode is run on a local Linux box?
And is there any obvious reason why ":uglifier" is not working? Thx.

Precompiled CSS File not found with rails 4 asset pipeline

I'm starting in rails and I've got an application that is working in dev (webrick).
The problem is: the precompiled CSS file is not found in production.
Now I host it on heroku and deploy it. I have a message saying that assets are precompiled (so it's not a compilation error) and everything is by-default for settings.
I've ls the /public/assets folder and everything is in there. I can even cat the application-*.css file and I get the full content I should have.
Now when I try to access the CSS file it gives me an error 404 (even tho it's an auto-generated css link usingĀ <%= stylesheet_link_tag "application", :media => "all" %>). So definetly it's not a problem that I did hardcode the CSS link.
I'm not exactly sure on what would be the next check to perform.
If you're curious on the output, it is currently publicly accessible here.
Try changing the configuration option config.serve_static_assets = false to config.serve_static_assets = true in your config/environments/production.rb if you haven't already done that.
The only thing that fixed it for me in Rails 4 was
config.assets.compile = true
in config/environments/production.rb
This would fall back to the assets pipeline if a precompiled asset is missed, according to the documentation.

Rails 3.1 Production - Javascript is missing .js endings on deployment

I've just made my Rails app and deployed it to Heroku. A very weird thing happened in the process though. Half of my javascript-files are missing their endings (.js). I have absolutely no idea why this is.I've searched far and wide, but I don't seem to find an answer.
My production-config looks like this:
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
config.assets.precompile << '*.js'
Any suggestions?
Posted this other similar question 1 hour ago (http://stackoverflow.com/questions/9049023/rails-3-1-production-javascript-loads-but-doesnt-execute). Sorry for the spamming.
Does this help? You didn't show where your js files are included. If they have dots in the name, apparently you need to tell Rails.
asset:precompile for .js files? rails 3.1

Rails 3.1 precompilation error in production for SWF file

I have a few .swf files that are being added to a project via a git submodule. They live in /vendor/private/widget/
To get the .swf files into the asset pipeline I'm doing the following:
config.assets.paths << "#{Rails.root}/vendor/private/widget"
In development this works just fine, but in production I get the following error:
ActionView::Template::Error (widget.swf isn't precompiled):
After searching around StackOverflow, I've tried these two solutions, both of which did not work:
config.assets.precompile << '*.swf'
config.assets.compile = true
Try setting application.rb 's
config.assets.digest = true
to
config.assets.digest = false
for the precompile, and flip it back to true afterwards. I don't know why this works or what part of the url digest would be preventing the asset inclusion, but this has been the only way i've found to be able to generate my assets in production to include swf files.

Resources