Successfully compiled resources are not displayed in the production environment? - ruby-on-rails

After compiling assets in production, old assets are displayed instead of new assets. Moreover, the compilation was successful and the file with the new assets is present on the server. I tried running rake assets:clean, it didn't help.
What could be the problem and how can it be solved?
I tried running rake assets:clean, it didn't help.

Related

Navbar from rails application disappears when deploying to Heroku

I have been building a Rails application that I am deploying to Heroku, I had installed a navbar to navigate around the app and it was working completely fine until recently. Now the navbar is not showing up on the application even though it still works perfectly when I try anything locally. I have tried rake assets:precompile, bundle install, and all the usual suspects. I don't know what to do exactly. I have attached screenshots of my app in testing and production. This is the image of the two apps. This error first turned up when I created an account on the production application on Heroku. The logs show this error
ActionController::RoutingError (No route matches [GET] "/assets/~bootstrap/scss/bootstrap")
So if a public/assets/manifest.yml(Rails 4 uses a file called public/assets/manifest-.json instead) is detected in your app, Heroku assumed you are handling asset compilation yourself and will not attempt to compile your assets. On both versions you can generate this file by running $ rake assets:precompile locally and checking the resultant files into Git.
This means that I ran rake assets:precompile locally, even just once, and then checked in that manifest file that would then need to run assets:precompile and check the results into git before every deploy. It's quite a subtle change that can catch people out.
Removing the public/assets/manifest.yml file from my git repo and re-deploying the app, so that asset compilation is done automatically by Heroku again solved the error.

CSS not loading in my Rails 4 app

Everything was working fine on my app, after I overhauled the entire front-end design. I attempted to push to my staging server on heroku, and I was getting issues when it was precompiling my assets. So, I attempted rake assets:clobber && rake assets:precompile, and now none of the css is loading in development at all. Syntax errors in my application.sass to bring up error pages, but it's not loading any of the css in my app. In chrome dev tools the only css files showing are SweetAlert css files.
I found the answer. I thought you had to precompile your assets in development, but after some research I found you do not. I clobbered my assets with rake assets:clobber and my css began loading just fine again. Also when pushing to heroku I did nothing else, since heroku precompiles your assets on deployment

javascript for the production no working

i am currently working for the javascript on the production , when i have done the assets clean , this problem has occurred.
The application works well with the development mode but doesn't work on production
please help.
Thanks
Atul Samage
rake assets:clean deletes these precompiled files.
run rake assets:precompile in your project folder
then you can commit these generated assets into the repository and proceed with deployment. No need to compile them on production machine.
Since precompilation is done in production mode only, no need to explicitly specify the environment.

Do you always have to run rake assets:precompile locally?

I read the docs but can't seem to understand if you have to run rake assets:precompile locally each time you change scss file or any other assets? Isn't there an automatic way to do it? One of the things I have noticed is that I forget to run it sometimes and my heroku changes do not appear. There must be a way to set it up automatically in rails?
If I change
config.assets.compile = false
to true, will do that it? Is a disadvantage of doing that?
You don't have to precompile your assets for Heroku to serve them. Heroku will precompile your assets automatically if you have not already precompiled assets locally. Read this heroku doc regarding the asset pipeline in Rails 3 (even if you are already using Rails 4). Then read this doc regarding the asset pipeline in Rails 4 on heroku.
Pay particular attention to this part:
If a public/assets/manifest.yml is detected in your app, Heroku will
assume you are handling asset compilation yourself and will not
attempt to compile your assets. Rails 4 uses a file called
public/assets/manifest-.json instead. On both versions you
can generate this file by running $ rake assets:precompile locally and
checking the resultant files into Git.
rake assets:precompile must be run for production environment. Do not need to run the command for the development environment. The command is used to collect all files into one and so be lighter to serve in production. Under development the styles they are wanted in the assets folder. After running the command, the styles are placed in the public folder.
If you forget to run rake assets:precompile Heroku should do it automatically. One reason it may not be is if you have checked your public folder into git as then during slug compilation Heroku will assume you precompiled your assets and will not do it for you.
Setting config.assets.compile = true can slow down your application by a lot, which is why it is only used in development.

Uncompile Development Asset Pipeline

I was compiling my asset pipeline for my production environment and it did for all my environments. How can I uncompile my asset pipeline for my development environment?
I have checked my config/development environment and cannot find a fix.
Thanks in advance for any help...
To remove precompiled assets use:
rake assets:clean
What this basically does is remove the public/assets directory. You may need to include the RAILS_ENV variable if you need to run it for a certain environment.
Try using
rake assets:clobber
worked for me in rails 4
When you run the compile task locally (on your development machine) the assets are compiled in the Rails production environment, but are written to the public folder.
This means that even when you run in development mode it'll use the compiled assets instead of sending requests to the pipeline. This is normal behavor - requests only go to the pipeline if the file does not exists in public/assets.
The compile task should generally only be used when deploying, and on the remote (production) machine.
If you have compiled locally, you can delete all the files in the public/assets folder and development will behave as before. If you checked these files into source control you'll need to remove them.
Once removed things should work fine.
s
One final tip: if this is an upgraded app check your config settings against those in the last section of the Rails asset pipeline guide.
For Rails 5:
$ RAILS_ENV=development bin/rake assets:clobber

Resources