ActiveRecord::Enum lets you declare an enum attribute where the values map to integers in the database, but can be queried by name.

Recently, I have been building a Rails RESTful-API and I found out about the enum feature in ActiveRecord. Let's see how you can use it.

blog_posts table schema

We will be building a very simple blog app where we have a BlogPost model to store the posts.
Notice that we are using int as the datatype for the state property. That’s because ActiveRecord::Enum stores the data internally as an integer and lets you use it as a string.
Advantages include smaller storage required, faster queries and indexes.

Let’s get started by generating an API-only app and get our hands dirty:

rails new blog…


Photo by Brooke Cagle on Unsplash

A first-year student

You got into college. Congratulations! ✨
Computer science is one of the most interesting fields, at least it is for me. My first day at college wasn’t the perfect one. I had no friends from my city. I was alone. So tip #1 is “Make Friends”. If there is one thing that I miss from my daily life at college it is my friends. Choose them carefully. 💕

Now to your first lecture, the one you will remember the most. I was lucky that Dr. Mahmoud ElGayyar was the lecturer back then. You should treat your doctors respectfully. During your…


Photo by Yancy Min on Unsplash

Using OSS Methods Can Lead to Producing a Better Product

If you want to build magnificent software it’s better to be an open-source project. having a great community of developers with cultures from all over the world is great. you will have a huge diversity of ideas, solutions, and contributions. you can get different people to look at your codebase with their different backgrounds according to their skills and knowledge, for example, you might have a security researcher finding bugs and vulnerabilities in your code. there might be a software architect out there giving you a piece of advice for your code.

building software takes time and resources as well…

Kerollos Magdy

Computer Science Student

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store