Image for post
Image for post
Photo by Caspar Camille Rubin on Unsplash

Getter and Setter methods in Ruby are gateways to access class instance variables. In this blog post I will explain how to create a class with getter and setter methods.

Let’s explain what a getter and a setter method in Ruby are!

A Getter method is the only way where you can retrieve the value of an instance variable from outside its class. A Setter method is the only way where you can assign a value to an instance variable from outside its class.

Now that we have an idea on what each one is, let’s explain them using an example. …


Image for post
Image for post
Photo by frank mckenna on Unsplash

A closure is a concept in JavaScript where one function has access to variables that belong to another function. The main thing about these two functions is that one lives inside the other where the inner one has access to the outer one’s variables. A closure is created whenever a function is created.

When a closure is created, it will have three scope chains: its own scope, the outer function scope, and the global scope.

  • It will have access to its own scope where any variable is defined within its body.
  • It will have access to the outer function variables.
  • It will have access to any global variable. …

Image for post
Image for post
Photo by Alok Sharma on Unsplash

Migration in Rails is responsible for creating and editing database tables. To migrate the database changes in rails, run $ rails db:migrate.
Rails will only read the new migration files that have never been migrated before. So once you run a migration file, you can’t go back and change it and run it again. You will have to create a new migration to edit your database.

In this blog post, I will show you how to manually create a migration file in Rails; whether it is a whole new table or fixing an existing table.

Create a table

You will have to create a new file in your db/migrate folder and you can choose a name such as 01_create_employees.rb. In this file, you will define a method within a class that inherits from Active Record. This method will create the employees' table. Here is a code snippet on how this file will look…


Image for post
Image for post
Photo by Joshua Aragon on Unsplash

Rails comes with a built-in script called Generator. It can produce many rails items that are necessary in every web/mobile application such as Models, and Migration. In this blog I will be explaining the Model Generator, how to use it, and how to customize it.

Model Generator

Model generator is one of the most common generators in Rails. Here is the command for the simplest one:

rails generate model Test

This command will generate a model called Test “app/models/test.rb” that has no attributes/class variables. The model will look something like this:

class Test < ApplicationRecordend

It will also create an empty migration for the Test Model, so that when you run it, it will create the actual table for this model. The migration file “db/migrate/create_tests.rb” will look similar to…


Image for post
Image for post
Photo by Jaye Haych on Unsplash

Rails is one of the best frameworks to create tables because it simplifies the process of creating and connecting these tables. However, in some situations, it requires slightly complicated steps to set up table relations. Let's take a money transfer example on a platform such as Venmo or Paypal. We would have User and Payment models/tables. They have a one-to-many relationship. A user has many payments and a payment belongs to two users, a payer, and a payee. So the Payment would require two references (user IDs) from the user table to be able to recognize the payer from the payee in a payment transaction. …


Image for post
Image for post

In my previous blog, I explained how you organize welcoming screens in your React-Native project. In this blog, I will show you how you can navigate from one screen to another by adding a link to each screen.

Let’s begin with setting up straightforward navigation actions, so each screen
allows the user to jump to another as follow:

  • When you are on the LoginScreen: you can navigate to both the HomeScreen and CreateAccountScreen.
  • When you are on the HomeScreen: you can navigate to LoginScreen.
  • When you are on the CreateAccountScreen: you can navigate to the LoginScreen.

Remember from the previous blog we are using the react-navigation-stack package which will carry down a navigation prop to each of your screens. We will be adding some buttons to direct the user between these screens. …


Image for post
Image for post

Welcoming screens are the first user interaction in any mobile/web application. They usually consist of three main screens, Login Screen, Create Account Screen, and Home Screen. In this blog, I will explain how to include these screens in your frontend React Native Project using the react-navigation package. Here are straight forward steps to help you organize these screens:

Installing react-navigation

First, you need to install the required packages in your frontend react-native project. The following command will install the dependencies to create the navigation structure in your application.

npm install @react-navigation/native

You will also need to installreact-native-gesture-handlerthat is used by this navigator.

npm install…


Image for post
Image for post
A joining table

Active Record in Rails has simplified database table relations. It made it much easier for the backend developers to connect tables together whether it is many-to-many or one to one.

In this blog, I will show you a simple way how to create a many-to-many relationship in your backend rails project. Open your project and follow with me step by step to tackle this complicated challenge in other programming languages and frameworks.

Pick your models

Decide which models that have a many-to-many relationship. For example, the relationship between authors and books.


Image for post
Image for post

If you have never built a mobile application and you wish to do so, then you are in the right place. This blog will show you some easy simple steps to create a simple Hello-World application that runs on your iOS device (iPhone).

There are many tools you can use in your first mobile application such as Expo, Ionic, NativeScripts, and many others. I’m going to be using Expo because it is a great tool that works across platforms (iOS, Android, Web, and even Desktop), therefore, you only need to write your application once. Also, the way you build and run your application is easy and straightforward. …


Image for post
Image for post

In one of my previous blogs, I explained the difference between Scopes and Class Methods in Rails. In this blog, I will explain two benefits of using Scopes instead of writing them as regular Class Methods.

What happens when you define a scope in Rails

Scopes are just methods that get converted internally by Active Record to Class Methods. For instance, a simplified implementation of ‘A’ student scope would look similar to this after it gets converted to a class method:

def self.a_student
where(grade: 'A')
end

That's why many developers don’t feel the need to write scopes instead of class methods believing that it is just another way or a syntactic sugar to write a class method. …

Shaqqour

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