10 things I add to every Rails app

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.


This content originally appeared on DEV Community and was authored by Pete Hawkins

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.

1. Tailwind CSS

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.

2. Authentication (Devise)

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.

3. Email systems

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.

Letter opener web

This gem makes sure you don’t embarrasingly send emails to real users whilst developing or testing, life-saver!

Postmark

Postmark is a service I have been using for years! It’s really easy to integrate into Rails using their postmark-rails gem, plus the product is great, easy to use and very reliable.

4. Admin system

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.

5. Tests

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.

For testing I use RSpec, along with shoulda-matchers for easily testing model relations & validations.

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.

6. Rubocop

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.

7. Sentry

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!

8. Sidekiq

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.

9. Metamagic

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") %>

10. Rack attack

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


This content originally appeared on DEV Community and was authored by Pete Hawkins


Print Share Comment Cite Upload Translate Updates
APA

Pete Hawkins | Sciencx (2021-10-02T16:25:19+00:00) 10 things I add to every Rails app. Retrieved from https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/

MLA
" » 10 things I add to every Rails app." Pete Hawkins | Sciencx - Saturday October 2, 2021, https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/
HARVARD
Pete Hawkins | Sciencx Saturday October 2, 2021 » 10 things I add to every Rails app., viewed ,<https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/>
VANCOUVER
Pete Hawkins | Sciencx - » 10 things I add to every Rails app. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/
CHICAGO
" » 10 things I add to every Rails app." Pete Hawkins | Sciencx - Accessed . https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/
IEEE
" » 10 things I add to every Rails app." Pete Hawkins | Sciencx [Online]. Available: https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/. [Accessed: ]
rf:citation
» 10 things I add to every Rails app | Pete Hawkins | Sciencx | https://www.scien.cx/2021/10/02/10-things-i-add-to-every-rails-app/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.