A Smooth train

rails...

·

2 min read

Hi y'all! Sup? Data is stored in databases. Duh! There are many types of databases but primarily,

  • SQL
  • NoSQL

Image for reference: (by twitter.com/swapnakpanda)

db_types.jpg

SQL -> Structured Query Language To query data from an R-DBMS, we can use SQL query to retrieve the data we want and how we want it.

Rails primarily deals with SQL databases but is also efficient in handling other types of databases. Now, to write complex plain-SQL to retrieve the data we want from huge databases will take quite a load of time and resources. Fortunately, to deal with data efficiently Rails uses ORM - Object-Relational Mapping.

Nope. Idk what that means. Google says...

Object-Relational Mapping (ORM) is a technique that lets you query and manipulate data from a database using an object-oriented paradigm.

Whatever that means. Simply put, Rails uses its own ORM to handle data efficiently and much easier than plain-SQL.

A formal disclaimer: ORMs definitely make it much better and easier to query and handle data but in no way means you need not learn SQL.

Alright! I am lost now. Back to rails. Last time we created a new model:

rails g scaffold Post title:string body:string
# g -> short for 'generate'

We now know a post has two attributes,

  1. Title
  2. Body

If you can run to your terminal and run:

rails c
# c -> short for console

In Rails console enter:

>>> Post.new

You will be replied with an object as below:

=> #<Post id: nil, title: nil, body: nil, created_at: nil, updated_at: nil>

Now before we go any further please don't make the mistake I made as I mentioned in my previous post.

I didn't really try and learn to understand Ruby presuming it was similar to other OOP languages like C++ and just skimmed through the docs for syntax, loops and other basics.

My humble and rightful request = Please watch this video!

Until then...

Love,

M.

liked_the_post == true ? comment and share : comment and share