Learn Ruby on Rails: Learn Ruby on Rails Series Part 12

In this series, we will continue the project that we created in the Ruby on Rails learning series, part 11. So for those of you who no longer have saved projects Homework management Please download the sample application at the following link [Download]

Before you begin, make sure that the homework management project you created is working well. If you’re sure, let’s get started!

Daftar Isi

Create a CRUD subcategory


As usual, open the terminal and execute the following code:

$ rails g scaffold sub_category name:string category_id:integer
$ rake db:migrate

By running this code, we created CRUD for sub_category and migrated it to the database.

The next step we add validation and relationships to the model subcategory :

After adding validation and relationships in the model subcategorywe also need to add relationships in the model category :

After adding relationships to the model categorywe add the following script to the controller sub_categories_controller :

  1. Add this method to the top of sub_categories_controller:
  2. Add the following method to the sub_categories_controller private section:

Edit sub_category views


We first modify the file app/views/sub_categories/_form.html.erb become :

We also modify the file app/views/sub_categories/show.html.erb become :

And above all, we change the file app/views/sub_categories/index.html.erb become :

By modifying these three files, we continue by trying to fill in the data for the subcategory. Run the following code:

Open the url in a browser, then we try to create a new data in sub_category. We fill it”Beginner 1” in the name column and select “English” as a category. Click create a subcategory to save.

Halaman Show subcategory

If you save the data successfully, your browser will display:

Halaman Show subcategory

Subcategory data added


To make the implementation of creating this drop-down list more understandable, we need to add a lot of data subcategory. Add the following subcategory data based on each category:


After finishing adding the existing data to the image, we can also add other sub_category data as per our wish.

Editing CRUD Assignments


Before changing the script in CRUD assignments, we first add attributes sub_category_id in the assignment structure by running the following code in the terminal.

$ rails g migration AddSubCategoryIdToHomework

Open the migration file in the folder database/migrateand add the following script:

Perform the migration by running the following code in the terminal:

We create a new relationship in the model homeworkby adding the following script:

Then we change the controller duty_controller look like the following:

Then we continue by changing the script app/views/homeworks/index.html.erb become :

And we also change the script on it app/views/homeworks/show.html.erb become :

After editing the index and viewing the assignments. We therefore continue by changing the existing script app/views/homeworks/_form.html.erb become :

By running it in a browser, you can see that in the form there are two drop-down lists. However, drop-down lists are not linked to each other. The sub_category dropdown data is not affected by the value of the category dropdown.

so congratulations!! You have successfully created a subcategory drop-down list

PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch