I end up creating a lot of Rails apps, and each time I get started I often find myself wanting to add similar features or gems that I’m using in other projects.
Here’s a short list of 10 of the most common things I add to every Rails app.
I’ve been using Tailwind now for almost 2 years, I am super productive with it and urge you to give it a try if you haven’t yet.
As Adam the founder says...
If you can suppress the urge to retch long enough to give it a chance, I really think you'll wonder how you ever worked with CSS any other way.
Check out my post below for the best way to use Tailwind with Rails.
Unless the project has really specific authentication requirements (like nine.shopping’s auth code approach), I’ll use devise to manage logins.
Alongside this, devise_masquerade is a fantastic plugin to use with your admin area, allowing you to login as other users. This is helpful for debugging account specific issues etc.
Wether it’s just for ‘forgot password’ emails, pretty much any Rails app I am building is going to send email. There are two handy tools I use for this.
This gem makes sure you don’t embarrasingly send emails to real users whilst developing or testing, life-saver!
I try to make all of my products as self-serve as possible, requiring as little of my time to set up accounts or keep the product running.
Because of this, having an in-depth admin system to allow me to check on things, block malicious users or make billing changes is necessary.
I usually tend to create these from Scratch, but moving forward I’ve started to use thoughtbot’s administrate gem. It sticks to the Rails conventions of controllers and routing, so it’s easy to customise and add new functionality to.
I am a big fan of TDD and having decent test coverage, this gives me confidence in continuously deploying code and ultimately helps me to develop apps faster.
I use Rails built-in fixtures instead of something like FactoryBot. This is purely for performance reasons, fixtures allow your tests to run much, much faster. Ultimately, I find a fast test suite is more useful and interrupts my workflow a lot less.
Sticking with the automated testing side of things, I like to use rubocop to make sure my code is consistent and it also catches some common issues with my code.
I usually follow the Shopify Ruby styleguide with a few minor tweaks.
Next up is error monitoring with Sentry. Exceptions usually happen in production when real users get a hold of your code, and making sure these are tracked helps a ton in seeing what’s going on and fixing it!
I often don’t set this up right away, but within the first week or two of development comes the time for background jobs. I like to stick with what I know and Sidekiq along with it’s web interface is easy to use and reliable.
This one is a small, but very useful gem. It helps set page titles, meta keywords and even open graph tags for sharing on social sites. This is a must if you have a lot of publicly accessible pages and want to start doing some SEO.
<% meta(title: "Sign in to your account") %>
The final gem I like to include in all projects is rack-attack. This is a rate limiting tool which is great for throttling dangerous actions in your app to prevent bot attacks or other malicious users.
It works great with APIs, but I also like to use it for login/sign up pages too, like so:
Rack::Attack.throttle("authentication/ip", limit: 30, period: 1.hour) do |req| if req.post? && %w[/users/sign_in /users/sign_up /users/password].include?( req.path ) req.ip end end