Why does rails remember deleted css? - css

For some reason, unknown to me, I am forced to precompile my assets when I deploy to Heroku. After I locally precompile and deploy, I obviously go back to changing my site. I have come across a problem where Rails "remembers" css rules that I have precompiled when I try to change them in my app/assets folder. I thought this might be because there is a new assets folder in public/assets and these styles might take precedence. I removed this folder and the problem still persisted. I can add css styles but I can not delete/overide css styles that had been previously precompiled. I searched these forums further and found CSS assets simply stopped to reflect any change. I tried it. However it has not fixed the problem. The only time I can get my css changes to apply is after I first change the style in my app/assets folder, then I precompile my assets locally, then only after I push to git AND deploy to Heroku will my changes reflect locally.
I would post code but I'm not sure what code would be relevant. Since what I'm talking about is a simple "border: 1px solid black;" style.
I think it is worth mentioning that after I deploy to heroku everything always works as intended.
Thank you for any help you might be able to give me.

Clean out your assets before you precompile anew:
rake assets:clean
otherwise your local machine may use the existing precompiled assets, rather than the new (changed) assets.

Related

Css changes are not being applied in rails app

I am working on rails app and now I am having trouble.
Early when I use to change my frontend styling and apply changes in css then they quickly show up on reload in brower.
But in present, don't know but something went wrong. Whenever I change css and save it then onload, things remain same.
After debugging, I found that app is picking styling files from precompiled assets pipeline. So for the solution, I have to recompile the assets then 2 new files are generated against wach file changed. And there will be 4 files in total against a single css file in which changes are made. So now I have to delete old ones and then have to restart the serve and refreshing the browser will show all the changing and that is weird as I have to do it all the time for every single change.
I can't figure as I am new to rails. Help....
Please clear the tmp cache first and then run the server
$ rake tmp:cache:clear && rails server
If you are developing the app, you should delete public/assets directory. Then restart the app. Don't run asssts:precompile task. Your most recent changes of assets will be up to date without restart the app.
I had the same issue and found a solution : run rake assets:clobber, it will remove the precompiled css and js. Then run yarn build --watch to build back the css and js file.
Dont run the assets:build as the same issue will revert.
This might actually be a browser issue, where the browser is caching the previous CSS and not reloading your new CSS changes.
Instead of reloading the page with CTRL+R, try reloading the page with CTRL+SHIFT+R
This will force a reload of the web page and clear the page cache, which forces all the assets to reload and fixed the problem for me.
No need to run css:clobber, assets:precompile, or anything like that! Just change the way you reload your browser :)
So I have find out the reason and it was because I have run the command of assets precompile which I shouldn't have to run as rails was doing it already for me may be due to configuration of my project or may it is its default behavior.
To solve this problem I have to delete my projects folder from my system and clone it again and things got normal again.
And now I never ever going to run assets precompile command again 😂

How to edit a scss file in django-cms?

I have been searching all over for information on where django-cms is storing the CSS and SCSS data for my site, which I am working on localhost. When I go to edit the CSS file directly, it has no effect, so I'm wondering what needs to be done to edit those CSS files. Obviously they have been loaded somewhere. How can they be reloaded, or in general what is the best practice for editing the CSS files?
Apparently I had to do this with both the style.scss and style.css files, which seem to have the same css classes. But even after editing both files, I had to refresh the site on my localhost a few times before I could see the changes. Frustrating, but it does work to edit the files directly in the static folder.
#Lawrence DeSouza At first you should mention which plugins and style frameworks you use.
If you are using some sort of a frontend framework like Bootstrap 4 your should compile its css from scss separately. You can do it right on the dev server in a separate directory outside your project dir and cloned from the official repository. Normally you would only need to change variables in "/bootstrap-4.x.y/scss/_variables.scss" file. On the next step you would compile your *.css files with "npm run dist" command and then copy compiled files from "/bootstrap-4.x.y/dist" directory to your "/projectname/appname/static/css" directory. The process is well-documented here. After copying changed files to your "static" folder you should run "python manage.py collectstatic" and refresh the page. If it's not working after refreshing the page in a browser (normally it should work) - restart the server. I am a bit biased towards Bootstrap, but the logic should be the same in your case.

Can't change the css in SuiteCRM

I am working on SuiteCRM, and i want to change the CSS of my website in order to personalize it but there is an issue.
When i am changing the "style.css" of the SuiteP Theme, the pages aren't changing at all. Here is my question:
Does someone know how to change the css of this CRM and can help me to fix it ?
Thanks a lot
Make sure that your active theme is "SuiteP".
You need to know that SuiteCRM store things inside "cache" folder and you are doing changes without refreshing cache files. Cache files location will be cache/themes/SuiteP/css/style.css. So for quick changes, you can use browser developer tools.
Moreover, if you change core style.css then empty cache directory and (hard)refresh your browser. If cache files don't exist then Suite will build new using core file.
Like Star previously mentioned, Suite does cache the CSS.
Though, if you're not updating the SASS file, and just updating the CSS directly, your changes will be temporary for when the CRM next re-builds the CSS (I believe this is part of the Repair and Rebuild process in the admin section), your changes will be lost as the CSS file constructed from the style.scss file.
I'd recommend installing sass (via a gem or other means, however you choose), making changes to the scss then recompiling the css (or watching for changes if working locally, which I hope you are for working with Suite) when you've applied your changes.
If you still don't experience changes, try a repair and re-build or delete the cache directory and let it recompile on the next page load.
there are 2 options:
change core file and then delete cache contents. Refresh your page twice.
made changes in cache file. Make sure developer mood is off. Once you are done then copy it core file.
Create a new subfolder CUSTOM, copy the CSS files that are under suiteP (or the current theme) into the new custom. copy the whole path with folders, even if the folders are empty.
So the new path for the sytle.css with be /costum/theme/....../css/sytle.css
Change the file under the custom folder. The previous answers are not correct. This is well documented under the suite CRM docs.
Sometimes it doesn't work. Try next steps:
SuiteCRM better to use in development mode.
Not always the cache files deleting works for me. Better to use the tool in Admin panel - Quick Repair.
Sometimes good to clear browser cache (in dev mode reload a page by right clicking the refresh button).

Rails 4; asset helper not pointing to fingerprinted image asset (failure to load in production # Heroku)

This problem is driving me crazy... I think I've tried every conceivable combination of Sass file, ERB file, asset helper, image helper, etc. etc. Someone please give me new ideas!
Context:
Rails apps require use of asset helpers so that when the assets are precompiled, the source will be a fingerprinted asset file. I.e., if you just called img src="X.jpg", the site in production would look for X.jpg, but the file in public/assets has actually been fingerprinted as X-as;diofua;wemfiwaejfoiawefo.jpg. The only way to get to that fingerprinted file is to use an asset helper, e.g., image_url ('X.jpg').
Right now in my live site, I'm using an asset helper, but for whatever reason, it's not pointing at the fingerprinted asset. Note that the assets are found in development (but again, that's because there's no fingerprint added in development).
Code
Image titled "classic-map.png", located in app/assets/images/galleria
Image is called from a css.erb file required in the application.css file. In the css.erb file, I have the following code:
background-image: url(<%= asset_path 'galleria/classic-map.png' %>);
For reference, http://guides.rubyonrails.org/asset_pipeline.html
Note that I'm choosing to write this as a css.erb file, hence the use of asset_path vs. asset-path. Also, I initially thought that the issue might have been in interpolation, but in the page source, the url is definitely working, it's just that it's pointing at url(galleria/classic-map.png) instead of url(galleria/classic-map-apsoidufalskjf;kasj.png)
A million kudos to whoever can help!
For what it's worth, this happened to be AGAIN, and this time I could not use the hack because I desperately needed the fingerprint. So somehow, magically, I ran a rake assets:clobber and heroku run rake assets:clobber to clean all assets, and then a straight up git push to force Heroku to do the precompilation for me. That did it, and everything works.
Now, when this happens, I clobber assets locally & in production and push, forcing Heroku to precompile remotely. Similar to #user2880239's answer. I have stopped precompiling locally and checking into git.
I sat with a Sr Rails developer who still couldn't help me fix this. But the workaround we ended up using was that we just manually removed the asset fingerprint in the public folder (since the fingerpoint is what the asset helper is meant to point to).
I.e., the file galleria/classic-map-587854758918434124.png we just manually changed back to galleria/classic-map.png and it works fine.
Note that if you do this 'hack', the next time you precompile assets, Rails will create another fingerprinted asset, so you'll have duplication unless you want to keep deleting the additional fingerprinted asset each time. For me, I don't care about the duplication, I care about not thinking about this anymore.
Did you check RAILS_ENV ?
bundle exec rake assets:precompile RAILS_ENV=production
I had the same problem you did. This blog post helped me.
What I did was change a few things in my config/environments/production.rb file, namely...
config.serve_static_assets = true
config.action_dispatch.x_sendfile_header = ‘X-Accel-Redirect’
config.assets.compile = true
Note that you might not need to 'add' any of those properties since they may be pre-set to false or merely commented out.
Then I did the heroku dance:
rake assets:precompile
git add .
git commit -m "Fix static assets"
git push
git push heroku
I'm having the same issue. I even tried the helper from the rails console from heroku, and the helper works fine there!!
$ heroku run rails console
Running `rails console` attached to terminal... up, run.8071
Loading production environment (Rails 4.1.7)
irb(main):001:0> puts helper.image_path("bg.jpg")
/assets/bg-00acfb7dbe138102509d82ac2313c24d.jpg
My final "solution" was to update config.assets.compile = true in config/environments/production.rb to fallback to the non fingerprinted image.
Hope this solution could help to someone. And if you had any real solution, please make me know!
The answer to this for Heroku is in their Pipeline docs here.
By doing clobber you are basically cache-busting all your assets and forcing all clients to reload all static assets (even if they have not changed) every time you deploy your code. That is not advisable as it means every time you deploy ALL clients will experience slow loading times until all assets get cached again.
Your css file has a dependency to your image file, so you need to tell the assets pipeline about this by putting this at the top of your css:
//= depend_on_asset "galleria/classic-map.png"
This tells sprockets that if class-map.png gets a new fingerprint then the css must also get a new fingerprint. So it will only recompile the files (and dependencies that changed).
Also for others landing here, be aware that if you are using asset_path from ANYWHERE other than a view (eg in a model) you need to prepend the full context:
ActionController::Base.helpers.asset_path('your-image.png')
More info here.

rails caching problem with css

I have two different css files... style.css and style_main.css
both are used separately in different layouts for the same application. In development mode everything works fine, but when in production mode, caching happens and both css files are loaded as all.css?xxxxxxx but unfortunately all.css is made from style.css and does not update with the change in layout. how do i prevent this???
When you deploy the code to the production server, you are probably also deploying the all.css file. Have you tried excluding this file from your version control system? When you update style.css etc on your development machine, commit the changes and then redeploy, rails will re-generate all.css if it finds that it isn't already in the public folder.

Resources