Yesterday, @davidteren asked what is the easiest way to setup TailwindCSS with Rails 8 and having hot reload.
This is how I believe it is to do so in a few minutes.
First thing is to add the tailwindcss-rails gem to the project and to run the installer to create the Tailwind config files:
And now you can run bin/rails tailwindcss:watch to rebuild the CSS files on file changes.
If you use CSS classes in a directory not watched by default, you can add that to config/tailwind.config.js under the content key:
And to make your workflow even smoother, you can use Foreman to manage all the necessary processes for you. To set that up is also pretty simple. Create a bin/dev file with the following content:
Then create a file, named Procfile in the root of your project with the following content:
After this, running bin/dev in your terminal will start the Rails server and the Tailwind watcher process.
That's it. It shouldn't take more than a few minutes to set this all up.
If you want to read this in a blog format and copy+paste the code snippets, here is a link to an article:
3 simple Rails security improvements you can do with a few minutes investment:
🧵👇
Even though Rails has secure defaults, there are still plenty of ways to shoot yourself in the leg, or to get compromised.
If you incorporate these 3 simple changes to your application, you will level up your application's security posture.
Setup dependency vulnerability monitoring.
Using dependencies with known vulnerabilities is a huge security risk.
To mitigate this, you can setup a Github action to run bundle audit and yarn audit on your codebase regularly and patch when needed.
One of Ruby's great features is method chaining.
For instance, Active Record heavily relies on this and method chaining enables us to do cool things like User.where("active = 1").count.
Have you ever wondered how is that possible?
Let's look into it, it is pretty simple.
🧵👇
Let's use a simple example of having a user model and you want to be able to set a default password for your user when they signup via OAuth. So you want to be able to do something like this in your controller:
Then in your model you would implement the set_password method: