Category: Tutorials

I saw a lot of projects where the default date format was used. In fact, customizing the date format to provide a human-readable date will be very welcomed from your customers! So what should we do to start making our application awesome? No worries, it’s a very easy process that we will discover together. Example To get started we will…

When should I use exists? or blank? to check records existence? Does this choice has an impact on our application? Asking those questions is a good sign of curiosity! So we will see together how those methods work under the hood and without a long introduction let’s unpack ActiveRecord and dive deep into the source code. Putting exists? under the…

In this post, we will see an approach how to safely drop a table from a production application without running into weird issues. As an example, we will use a simple blog that allows adding comments to each post and also has a simple stats table where it tracks likes, views, and shares of posts. The model diagram for this example is…

Choosing a good name for a class or a variable isn’t easy at all and sometimes there is a requirement to rename existing tables and models to match the updated product audience. So how we should do this migration then: 1- Ask why The first step is to ask why should we rename the model, with a productive mindset and…

We saw previously in this post how to add uniqueness database constraint for a single table. But in real-world applications, we have different associations between models, so let’s start with an example: We have a service platform where a user can buy subscriptions for different services, the requirements are the following: A user can have many subscriptions for different services…

It’s easy to use model validation in Rails application and in this article, we will study some aspects with the uniqueness validator. So let’s start with an easy requirement, we want to have an Account model with a unique email attribute.

Ruby

1

2

3

4

5

classAccount<ApplicationRecord

validates:email,uniqueness:true

end

This solution works but it’s not enough. For beginners, it’s important to understand how validation work in Rails.…

In the first part, we saw some guidelines for choosing a Gem, in the following post we will discuss updating gems which is an important use case for real world applications. When to update? Most of the available Gems in the ecosystem will receive some patches and updates. So we should check our installed versions for security fixes and performance improvement.…

Ruby provides a variety of Gems for every requirement and new developers get confused when choosing the between Gems. So I’ll share my personal guidelines for choosing a Gem: 1 – Check if the Gem is maintained: You can verify if the author mentions in the documentation that this gem is not actively maintained for example Test Benchmark Gem, so in…