Problem with JS/TailwindCSS initializing/compiling - ruby-on-rails

I am developing a food recipe app but got stuck and have a problem with javascript and css(Tailwind) assets. Both Javascript and new tailwinf codes not compiling at all. It was fine before but when i was deleting carrierwave gem i accidentally remove public/assets folder because i was going to use active storage for that purpose(image uploading), now even if i do rails assets:precompile, it doesn't change anything. Old tailwind codes works just fine but newly written tailwind codes that i didn't use before doesn't work even if i run server with ./bin/dev. I don't know which part of my code should i share so i can share GitHub link of my project. Thanks it advance.

Related

Rails does not update the fingerprint for some assets

I notice there is a weird thing going on in rails 4.2.0. I am using the default dev environment. When I change some of my JS files, the fingerprint does not change and it keeps serving the old file. The weird thing is that this does not happen to all my JS/CSS files. I tried rebooting my machine and restarting rails server. None of them worked. Renaming the file works, but when I rename it back to the old one, it starts serving the old version again. Anyone has an idea why?
Make sure to set config.serve_static_files = false in your config/environments/development.rb and to reset your browser cache.
I am not sure if we have the same situation, but hopefully this helps.
Reference
I was using a custom application-all.scss instead of the normal application.scss stylesheet in which application-all.scss used to be part of Rails.application.config.assets.precompile.
I renamed application-all.scss into the digested-name application.scss, and updated related code.
After that, it worked now for me.

Bootstrap-sass gem not loading

Ran into an interesting problem and wondered if anyone else has as well.
I'm doing a Rails tutorial and part of the setup is installing the bootstrap-sass gem. The tutorial recommends for installing bootstrap, to rename the existing application.css file to application.css.scss, removing all the contents in that file, and then adding #import "bootstrap";.
I downloaded the tutorial's source code and ran it on my local machine and it works just fine.
However, when I implemented this in my code, no css stylings appeared. No errors appeared in the logs, either, though I noticed there was no GET request for the css occurring. I even went into the source code, clicked the css file and it appeared empty, while all the bootstrap javascript files were not empty.
After a while, I decided to implement bootstrap in the way that several other tutorials had done - I put the application.css.scss file back to its normal application.css file with all of the default contents that appear there, and then created a new file that I called styles.css.scss and put in the #import "bootstrap"; there and it loads it just fine.
I contacted a mentor of the program teaching the tutorial. He downloaded my source code from my github repo and saw exactly what I saw, though his project was working just fine, and no other students of the program had yet reported an issue doing it the way that the tutorial (and the bootstrap-sass docs) suggested.
Has anyone else ever run into this issue?

Rails with Twitter Bootstrap: still serving an old asset

Going nuts here. I'm developing a rails app, and I'm using the twitter-bootstrap-rails gem in order to include the Twitter Bootstrap styles in my app. This gem generates a file called 'bootstrap_and_overrides.css.less' in app/assets/stylesheets, which I have been using to modify some of the bootstrap variables and include my own CSS overrides.
Everything has been working fine until today. For some reason, the changes I am making to this file today are getting saved to the file, but Rails is still serving the old version of the file! I've searched and found no precompiled versions of the file anywhere (nothing in public/assets)...only the one in assets/stylesheets which I have been modifying. Everything looks fine as far as the directories within the app go, but then when I start the rails server, load the page, and use the element inspector to look at the stylesheets, it's using an old version of 'bootstrap_and_overrides.css.less' with rules that I have deleted. I've turned of the cache in my browser, and tried it in 4 different browsers too, so I'm pretty sure this isn't a result of browser caching.
The rails asset pipeline just seems to serving a version of the file that doesn't exist! Does anybody have any ideas why this might be happening?
Fixed it.
The asset pipeline was storing a cached version in tmp/cache.
I ran rake tmp:clear, which deleted all the files in there, and then rails served the version of *bootstrap_and_overrides.css.less* that I wanted.
Why the cached version suddenly stopped getting updated is beyond me. Arrghhhh!

Rails 3.1 .css.less caching error

I am quite new with Rails and I am having some irritating problems with caching of css files.
I have a .css.less file with imports inside it. It's the only stylesheet the app includes, so the other files get imported only once and by this unique stylesheet.
One of those imported .css.less stylesheets seems to be cached somewhere, because does not change in the browser when I change it's source.
I can only see the changes I made if I change something in the root stylesheet.
I have the server in development mode, so the caching should be off. I have also used <%= stylesheet_include_tag "style", :cache => false %>
I tried with Chrome and Firefox, with and without clearing their cache too. Always the same result, if I work only on that file the css the page receives when reloaded doesn't have the changes...
I also stopped the server and rm everything in the tmp folder of the app. No changes.
I am using Rails 3.1 with Ruby 1.9.3, with the less-bootstrap-rails gem. Both the root stylesheet and the imported one have .css.less extension.
What am I missing?
Thank you!
This is an area where I think the asset pipeline is broken, but I don't think there's a good fix.
If I remember correctly, to get changes in files you've included/required in your .css.less file, you need to change the .css.less file itself.
I had this on Rails 4.0.8, infuriating. The config changes mentioned above didn't help. Here's what seems to have fixed it for me:
Ensure NO FILES share a base name. For example, you have a reports.css.less and a reports.js.coffee? Doesn't matter if they're in the same directory or not. Rename or delete one of them. (I changed it to reports-styles.css.less).
Blow away your cache: rm -rf tmp/cache
Restart your Rails app.
This appears to be a decent fix but, since I don't know what's actually going on, this could be totally false and it's just working by coincidence now. Sorry this answer isn't more rigorous!
I've just came across the exact same problem.
I found that if you rename your *.css.less file (the one with the imports inside) to *.less, then this weird cacheing problem gets resolved.
Add this to your config/application.rb
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
See more at: Ruby on Rails Guide: Asset Pipeline

What is the Ruby on Rails assets directory and how do I get it in my old app?

I'm new to RoR and started making a project recently. The project has public/stylesheets and public/javascripts for my CSS and JS.
For testing purposes, I created another RoR app called sample_app to play around with. I noticed sample_app has an app/assets directory where you can use CoffeeScript and SCSS! That's really cool!
However, my primary app doesn't have that stuff.
Can someone explain what is going on here, and how do I upgrade my first app to use CoffeeScript?
Also, does it matter that my first app has a model called Asset? I could rename it if necessary... heck, I could just create a new app if necessary and move all the old code over manually. It'd be worth it to use CoffeeScript instead of JS.
Thanks!
Rails 3.1 is currently in beta (technically, release candidate 3.1.0.rc1).
Take a look at the generated files in sample_app. Particularly config/*, config/initializers/*. Copy any differences to your existing app.
Replace the gem 'rails' line with gem 'rails', '3.1.0.rc1' in your existing app's Gemfile.
Copy app/assets to your existing app
Run bundle update
rails generate controller some_test_controller will give you an idea of where Rails is putting/using the new app/assets.
Move things from public/javascripts and public/stylesheets to app/assets/**/*
Keep in mind, rails-3.1.0.rc1 should be fairly solid, but it is a beta release. Make sure you've got stuff committed / backed up before starting

Resources