Ruby on Rails & CRUD

At one point every developer begins to understand the core fundamentals when it comes to building out any application. We start realizing every popular app out there follows these four basic actions, from instagram to Tik-Tok everyone on these apps uses these functions on a daily basis. Although how these actions are implemented may be different they all stem from CRUD. So what is CRUD? and why is it important in Rails?

CRUD stands for Create, Read, Update, and Delete. Every app is different but these functions are in every single one, how they are implemented is up to the developers. In Rails each CRUD has multiple actions and these actions are what give the user the ability to use these actions in the app they are using. Rails is a powerful framework that follows convention over configuration, meaning we spend less time building out files and more time building out the actions themselves.

In Rails we follow a pattern in order to create these actions and it all starts within our routes, what is a route? Well a route provides URL rewriting in Ruby language by using controllers and actions. Our routes can be seen in the table above (Example URL) but thanks too Rails we are able to perform all functions simply by using the word resources. Rails is our best friend and provides us with everything we need to create a web app in the fastest way possible.

Routes

Rails does most of the work for us but we still have to create individual HTML pages for every controller action in order for Rails to display what we have written inside these files. For the most part Rails follows a simple pattern routes => controller => views this pattern is essential for our code to work properly. If we successfully follow RESTful routing and build out our core actions we can create a very simple webpage using CRUD.

User Index Page
User show page
Elvis’ Post show page

Rails is a wonderful developer tool that makes it easy for us to turn lines and lines of code into a working web app. As any other developer we are lazy and thanks to Rails it saves us time while feeling like we didn’t really do much in the first place. Everything that can be seen from these web pages on our localhost:3000 came from Rails and it transformed the image below into what we have in the images above. We this we are able to see just how powerful Rails can be and of course there is much more to it than these couple of lines of code.

User Show Page

CRUD is everywhere, and it’s our job as developers to ensure the user is able to experience these actions without any issues. As i continue my journey into becoming a full-fledged developer i will always remember the importance of CRUD and make sure to take it into account when creating my next application. It’s important to note no matter what programming language or framework we use the ideas are the same and in the process of creating our applications we should always think CRUD.

--

--

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