In one of my previous blog posts, I explained how to create a full Rails application using the Scaffold generator. However, in many cases, you will need Rails to serve as your backend application that renders APIs to the frontend application. In this blog post, I will show you how to create a backend Rails application as an API.
As always we will start by creating a new Rails application using
rails newcommand. Let’s run the following command in the terminal:
$ rails new rails-application
Running this command will create a full Rails application that would also serve as a…
React Router is a library or a package to help you navigate between your React application components. As mentioned in React Router’s Documentation, “React Router is a collection of navigational components that compose declaratively with your application. Whether you want to have bookmarkable URLs for your web app or a composable way to navigate in React Native, React Router works wherever React is rendering — so take your pick!”
In this blog post, I will show you how to use React Router with a code along for a song library. Let’s get started:
This is an easy step. All you…
If you are new to Rails, you might come across Scaffold generator. So what is scaffold generator in Rails? In this blog post, I will show you a code along with an example of how to use it.
“Scaffolding, also called scaffold or staging is a temporary structure used to support a work crew and materials to aid in the construction, maintenance and repair of buildings, bridges and all other man-made structures.” — Wikipedia
Now that you know what scaffold is in general, you can have an idea of what scaffold is in Rails. A scaffold in Rails is a…
In one of my previous blogs, I explained how to create your first react-native project. In this blog post, we will create a project that updates the
state when typing in a
TextInputor by clicking a button.
We know from the previous react-native blog post the way to create a new project using Expo client to run your app on a web browser or you can even run it on your device. In your terminal run the following command and then when prompt choose
$ expo init counter
After you create a new react native project, if you…
In one of my previous blogs, I wrote a blog post on how to use the Model generator in Rails. In this blog post, I will explain how to use the Resource generator.
As we said before, generators in Rails is a built-in script that produces many application elements. The Model generator produces a model (class) inside the
app/models directory, a migration file inside the
db/migrate directory, in addition to some unit testing files. However, the Resource generator produces more than just these elements. Let’s talk about this in detail.
You can write the command to create your resource specifying the…
Scraping in Ruby is a way to extract data from web pages so you can use it in your program. We usually scrape data when the website doesn’t provide raw data, APIs for instance, for the information we need. So we just pull the web page to our program and extract some raw data from it.
For example, this web page presents the best 300 movies to watch according to Rotten Tomatoes.
A big part of Ruby programming is based on making the programmer life’s easier and better. Macros in Ruby were created so programmers don’t write the same things over and over again. So what is a macro in Ruby?!
A macro in Ruby is a piece of code that is responsible for generating other code which could be a new instance method. In my previous blog post, I explained how to write Setter and Getter methods in Ruby. …
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…
When a closure is created, it will have three scope chains: its own scope, the outer function scope, and the global scope.
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.
You will have to create…