I'm running into a bit of an issue on one of my first rails projects.
Locally, in development, my website is displaying perfectly. Fonts are being loaded correctly and the background image is displaying on every page. On Heroku however, the fonts do not appear, nor does the background image.
I have tried running the following commands
RAILS_ENV=production rake assets:precompile
RAILS_ENV=production rake assets:clobber assets:precompile
RAILS_ENV=production rake assets:clean assets:precompile
heroku run rake assets:precompile
heroku run rake assets:clobber assets:precompile
heroku run rake assets:clean assets:precompile
None of these commands changed the way the app was displaying, I also made sure to clear cookies before each attempt and even view in incognito; everything to no avail.
I also attempted to change how the background image was being introduced into the project.
* I changed the custom css file to end with a css.scss
* I altered the css call from background: to background-image:
... This caused the background image to fail to load locally as well
*I altered the css call from url('../img/bg.jpg') no-repeat center center fixed; to
image-url('../img/bg.jpg') no-repeat center center fixed;
... Again all this did was cause the image to not be loaded locally
I tried doing a combination of those two, again, to no avail.
I have both my css files and my image files located in the appropriate folders inside of the app/assets directory. The files are actually showing up inside of the public/assets folder as well, but still, the website does not display the fonts nor the background image.
I am very confused, and frankly out of ideas. Is there any thing I missed? Can anyone offer me some more ideas?
In you gemfile add gem
rails_12factor
Try this ..........
By default Rails 4 will not serve your assets. To enable this functionality you need to go into config/application.rb and add this line:
config.serve_static_assets = true
Alternatively you can achieve the same result by including the rails_12factor gem in your Gemfile:
gem 'rails_12factor', group: :production
This gem will configure your application to serve static assets so that you do not need to do this manually in a config file.
Please have a look here https://github.com/heroku/rails_12factor#rails-4-serve-static-assets
Hope this will work for you.
Related
My assets are not being properly precompiled to my staging heroku app. I usually use rake assets:precompile before pushing but my senior developer told me not to use that and put /public/assets into gitignore saying that heroku will automatically precompile the assets. When I push, heroku says that it runs rake assets:precompile but none of my assets show up. The page is just html.
possible causes: before my senior developer told me his way, I ran rake assets:precompile and removed /public/assets from gitignore as I though it wasn't suppose to be there. But after he told me, I put /public/assets back into .gitignore and deleted all the public assets and the assets still are not working on the heroku staging app. What am I missing?
I found the solution here: https://stackoverflow.com/a/16571492/1890135
I didn't specify this in the question but I was making a 2nd staging app not called staging so I had to add the rails_12factor gem under this new staging name environment.
group :staging_new, :staging, :production do
gem 'rails_12factor' # To enable features such as static asset serving and logging on Heroku
end
Why did you include public/assets in your gitignore file anyway? There's no need for it to be in there, unless you've precompiled your assets locally & don't want to use them in Heroku?
--
A good way to test whether your app will work in staging is to run rake assets:precompile RAILS_ENV=production. This will do as Heroku would -- compiling your assets
What I would do initially is:
Precompile your assets locally (using rake assets:precompile RAILS_ENV=production)
Check in your public/assets folder for the precompiled files
If they're there, push to Heroku & do again
If not, there will be another problem to fix
Generally, though, Heroku's precompilation process is just the same as you would do locally. So maybe you could even try running your Rails server in production mode to see what the issue might be; it's probably more your app than Heroku
When i run the website locally, it works fine.However, after pushing to heroku, its displaying as a broken image
The pictures are in my /assets/images/ folder
images are called in my static page like this
<img src="assets/blank_avatar_male.jpg" alt="blank_male_avatar">
Ive tried changing the path to /assets/images/jpeg and it and repushed. No luck so far.
Any suggestions on how to fix this?
My guess is that you don't have config.serve_static_assets set to true in your production.rb file.
The simplest solution is to include the rails_12factor gem which will do this for you
try compiling your assets locally like this:
RAILS_ENV=production bundle exec rake assets:precompile
and then push to heroku
I was originally using bootstrap for a bit of prototyping but then I removed it. Now, I'm trying to push to Heroku, but keep getting this error:
Running: rake assets:precompile
rake aborted!
File to import not found or unreadable: bootstrap.
Load path: Sass::Rails::Importer(/tmp/build_1xogapzflu9oq/app/assets/stylesheets/custom.css.scss)
(in /tmp/build_1xogapzflu9oq/app/assets/stylesheets/custom.css.scss)
Of course it's unreadable because I removed bootstrap. Why is it still looking for it? I deleted everything in tmp, custom.css.scss doesn't even exist in my stylesheets, and there's no mention of bootsrap anywhere in my app! I've also tried deleted and recreating Heroku app.
What's going on here that I'm missing? Thanks!
Edit: rake assets:clean did not do anything either before heroku push or after.
Check your app/assets/stylesheets/custom & app/assets/stylesheets/application files & remove bootstrap's //=require directive, if present.
Further, if problem still persists. do the following
$ git add .
$ git commit -am "bootstrap fix"
$ git push heroku master
Lastly, if you still get the error. Paste your app/assets/stylesheets/application file, so we can debug what's going on
If you have bootstrap gem etc, remove it from Gemfile, and put your bootstrap css and js files manually in proper assets folder.
Once I've done bundle exec rake assets:precompile RAILS_ENV=production
It seems that it created something like application-e24jrjf834jg93bwuk13uy5gfd1y24f.css
Then when I access to the page, that is called from my app.
In development mode, I could add changes to just to css file and it applied.
In production mode, can I still add little changes to css?
If possible, how?
If you have set config.assets.initialize_on_precompile to true in your production.rb file then all you need to do is restart your server. Otherwise just delete the precompiled assets by running bundle exec rake assets:clean and precompile assets again bundle exec rake assets:precompile RAILS_ENV=production.
I am developing an application with Rails 3.0 and Backbone and I tried
asset precompilation (rake assets:precompile).
Since then any change I made in the code is not reflected in the executed application,
in development environment.
Thank in advance
You'll have to pre-compile assets every time you make a change.
rake assets:precompile RAILS_ENV=development
I proposed a possible cause and solution to a similar question here which relates to
config/application.rb containing files to be precompiled.
I am writing with respect to Rails 3.2.22
if you are facing this problem then here is solution:-
Causes
Since you are run rake assets:precompile the script has created a folder public/assets and generated all the assets file the browser might ask for. So, when you make new changes in the js/css asset files, the requests from browser are served from public/assets directory.
Two Solutions
rm -df public/assets
rake assets:clean