What is a callback function?

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

Here is a quick example:

function greeting(name) {alert(‘Hello ‘ + name);}function processUserInput(callback) {var name = prompt(‘Please enter your name.’);callback(name);}processUserInput(greeting);

Why and when we should use callbacks?

The above example is an asynchronous callback, as it is executed immediately.

Let’s think of a different scenario. Suppose:

  1. when we get success response, we want to use this response data


HTTP Request methods:

Two commonly used request methods are GET and POST.

GET:

GET is used to request data from a specified resource.Note that the query string (name/value pairs) is sent in the URL of a GET request:/test/demo_form.php?name1=value1&name2=value2

POST is used to send data to a server to create/update a resource.

The data sent to the server with POST is stored in the request body of the HTTP request:POST /test/demo_form.php HTTP/1.1Host: w3schools.comname1=value1&name2=value2

How PUT, PATCH, and DELETE methods work with Rails/ HTML form:

It is very easy to make different types of requests like PUT, DELETE, etc. …


Active Record is the M in MVC — the model — which is the layer of the system responsible for representing business data and logic.
[Source: https://guides.rubyonrails.org/active_record_basics.html]

Rails Active Records provide an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records. Ruby method names are automatically generated from the field names of database tables.

Each ActiveRecord object has a CRUD (Create, Read, Update, and Delete) methods for database access.

This strategy allows for simple designs and straight forward mappings between database tables and application objects.

[Source: https://www.tutorialspoint.com/ruby-on-rails/rails-active-records.htm]

When we want…


What is RVM

RVM is a command-line tool for managing multiple ruby versions and also uses a separate gemset for each rails app.

RVM is a command-line tool that allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
[ source: https://rvm.io/ (official rvm website) ]

Ruby Version Manager, often abbreviated as RVM, is a software platform for Unix-like operating systems designed to manage multiple installations of Ruby on the same device. The entire ruby environment including the Ruby interpreter installed RubyGems, and documentation is partitioned.

[ source: Wikipedia ]

Why we need RVM

Let’s see an example.

Suppose…


Photo by houghtco.com

Introduction:

First of all, the Enum is very easy.

When I started using Ruby on Rails I was questioning myself, when I can use a string attribute for some record type or status why I do I need to use Enum.

In this article, I wanted to share my understanding of Enum or Enumeration.

How Enum stores data in the database:

Normally, in the database enum is an integer, and when reading this attribute from an object of a model, It is converted to a string.

Suppose,

  • This Order model is an attribute order_status
  • There are 3 orders status: pending, delivering


What is a webhook?

Webhooks are user-defined HTTP URL, where other servers/apps can send messages.

When a specific event has occurred on a third-party server, that server can send data to our server with that webhook URL.

Webhook: technical explanation

Suppose, When a developer pushes git commits to our repo, we want to show that in our chat channel. What can we do for that? With a minute interval, we can check the git server for new git commits. and a developer pushes a commit after 1 hour. So, we tried 60 times in an hour and then we got 1 new commit.

We can do it…


What is rails migration:

Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don’t have to write SQL manually, allowing your schema and changes to be database independent.

[Source: official rails guide]

Simply we can say, when we need to create a database table, we can change a database column or delete a database column, we write a database migration.

Supposed, when we create a model, we need to create a database table for this model, then we create a migration to create a database table.

Why do we need to learn about migration:

When we create/generate…


Source: https://www.sitepoint.com/

What is a Ruby Hash:

Simply, A Hash is a collection of key-value pairs.

It is similar to an Array. But in Array, indexing is done via integers.

While in Hash, indexing is done via Objects.

Normally a String or a Symbol is used as a hash key.

Creating a Hash:

Create a hash with the Hash class and insert the items:

users_age = Hash.newusers_age["John" => 26]users_age["Maria" => 22]users_age["Robert" => 28]
users_age["John" => 26, "Maria" => 22]users_age["Robert" => 28]

You can use the Symbol as a Hash key:

users_age[:john => 26…


Source: https://www.deviantart.com/

What is a symbol in Ruby?

Symbol objects represent names and some strings inside the Ruby interpreter. They are generated using the: name and : “string” literals syntax.

Source: https://ruby-doc.org/core-2.6/Symbol.html

The symbol is written with a preceding colon ( : )

Example:

:small:is_admin:developer

What is a string in Ruby?

A String object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String objects may be created using String::new or as literals.

Source: https://ruby-doc.org/core-2.6/String.html

The string is written with double-quote or single quote:

Example:

"hello world"'another example''boom'

Why do we use symbols over strings?

The symbol is immutable and allows Ruby to use the same object every time.

Example:

# 1a = :hello


Source: https://vietnamhtmlfactory.com/

What is jQuery?

jQuery is a lightweight, “write less, do more”, JavaScript library.

The purpose of jQuery is to make it much easier to use JavaScript on your website.

jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish and wraps them into methods that you can call with a single line of code.

jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.

Source: https://www.w3schools.com/

jQuery promotes simplicity:

jQuery is easy to learn. It has simple code syntax. Developers can easily implement functionalities with jquery. …

Jam

Software engineer | Full Stack Developer | Programmer | Designer & Entrepreneur

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