Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RoR - 1 - Gems

Fourth day of the 42 Ruby on Rails Piscine. This module dives into Gems, pieces of reusable Ruby code that you can share and use in different contexts and culminates in first Rails application.

Map

module map

Generated with lsphere.


Vagrant Setup

All exercises run inside a Debian 12 VM managed by Vagrant. Provisioning is split into two steps:

  1. Ruby — installs rbenv + Ruby 3.3.6 + Bundler
  2. Rails — installs the Rails gem and sets up the ex03 Hello World app
vagrant up          # first boot: provisions everything
vagrant provision   # re-run provisioning on a running VM
vagrant ssh         # open a shell inside the VM

Port 3000 is forwarded from the VM to your host, so http://localhost:3000/ works from your browser once the Rails server is running.


Exercises Overview

Exercise Path Topic Description
ex00 ex00/ Your first Gem A gem that answers the ultimate question of life
ex01 ex01/ Open-URI + Nokogiri Crawls Wikipedia links until it reaches Philosophy
ex02 ex02/taillste/ Bundler gem scaffold A gem with Drum, Beat_box & Clap classes
ex03 ex03/ Rails intro First Rails app displaying "Hello World!"

ex00 - deepthought

Path: ex00/ Gem name: deepthoughth

A gem that defines the Deepthought class with a respond(question) method. When asked "The Ultimate Question of Life, the Universe and Everything" it returns "42" (in green); otherwise it returns "Mmmm i'm bored" (in red).

Dependency: colorize ~> 1.1.0

cd ex00
gem build deepthought.gemspec
gem install deepthoughth-42.0.gem

Reference: https://guides.rubygems.org/make-your-own-gem/

The colorize dependency must be declared in the gemspec — otherwise the gem installs but raises a LoadError at runtime.


ex01 - ft_wikipedia

Path: ex01/ Gem name: ft_wikipedia

A gem that defines Ft_wikipedia with a class method search(start). Starting from any Wikipedia article, it repeatedly follows the first valid content link until it reaches the Philosophy article. Raises DeadEnd if a page cannot be fetched and LoopDetected if a cycle is found.

Dependencies: open-uri ~> 0.4.1, nokogiri ~> 1.19.1

cd ex01
gem build ft_wikipedia.gemspec
gem install ft_wikipedia-1.0.gem

ex02 - taillste

Path: ex02/taillste/ Gem name: taillste v0.1.0

TDD driven, fix the code to make all tests pass

cd ex02/taillste
bundle install
rake test
gem build taillste.gemspec
gem install taillste-0.1.0.gem

ex03 - Hello World Rails

Path: ex03/hello_world/

Your first Rails application. The root page (http://localhost:3000/) displays an <h1>Hello World!</h1> heading.

Setup (inside the VM)

The provisioning script ex03/setup.sh handles everything automatically during vagrant up. To run it manually:

vagrant ssh
bash /vagrant/ex03/setup.sh

Starting the server

vagrant ssh
cd /vagrant/ex03/hello_world
bundle install
rails server -b 0.0.0.0

Then open http://localhost:3000/ in your host browser.

What the setup script does

Step Action
1 Installs the rails gem (gem install rails --no-document)
2 Runs rails new hello_world with minimal flags (SQLite, no mailers/cable/etc.)
3 Adds root 'home#index' to config/routes.rb
4 Creates HomeController#index
5 Creates app/views/home/index.html.erb with <h1>Hello World!</h1>

Key files

ex03/
├── setup.sh                          # provisioning script
└── hello_world/                      # Rails app (created by setup.sh)
    ├── config/routes.rb              # root 'home#index'
    ├── app/controllers/home_controller.rb
    └── app/views/home/index.html.erb # <h1>Hello World!</h1>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages