Giter Club home page Giter Club logo

i22's Introduction

Ruby on Rails Introductory Exercise

This is an interactive exercise introducing web development with Ruby on Rails 7.0 based on the v6.0 Rails Guide. It is used in HPI's SSE course.

This exercise is inspired by the offical "Getting Started with Rails" Guide in version 6.0 (explictly in version 6.0, v7.0 is different). So in case of getting stuck, the v6.0 guide is a good starting point to find solutions.

The interactivity of this exercise is provided by opening issues in the GitHub issue tracker. The issues contain details of the feature to tackle next as well as the currently failing test case and the corresponding error message.

This repository contains an application stub of an academic paper management system with a failing test case. Follow these steps to complete the software and the exercise:

Exercise Steps

1) Set up your repository

  • Ensure that the issue tracker of your repository is active (i.e. an "Issues" tab is visible). If not, activate it in the Settings tab on the GitHub website.

drawing

2) Set up local development environment

Three options to setup your local Ruby on Rails development environment:

Option 1: Local setup on Linux or MacOS

  • You already have access to a Linux-like environment. Install Ruby (on Rails) directly on your OS

Option 2: WSL in Windows

Option 3: Use a Virtual Machine

  • We recommend Virtualbox (as a VM provider) and Vagrant (to manage VMs) in combination with Ubuntu Linux.
  • Any other container solution, such as Docker will also work.
  • You may want to share the file system with the host OS to use your locally installed tools.

After you have access to a Linux-like shell:

  • Clone your exercise repository using git clone. Cloning via SSH instead of HTTPS avoids having to type credentials when pushing.
  • In the newly cloned folder (cd into it), check the Ruby version: ruby --version. It should be 2.7.4 (or higher).
  • If the correct Ruby version is not used, install a ruby version manager: either rbenv including ruby-build) (recommended) or RVM.
  • Install the required Ruby version: e.g. rbenv install 2.7.4 (might take a few minutes, requires ruby-build)
  • The .ruby_version file in the repository instructs the ruby version manager to use the correct version.
  • Please let the teaching team/your fellow students know if there are problems. Most likely someone else has had similar issues already and can help.

3) Dive into the code

  • Run bundle install to install the dependencies of the project (they are stored in the Gemfile)
    • If the bundle command was not found, install bundler with gem install bundler
  • Run rails db:migrate RAILS_ENV=development && rails db:migrate RAILS_ENV=test to migrate the database
  • Start the development server (rails s) and check that the application runs (default: http://localhost:3000/). When running in WSL/container: rails s -b 0 # -b required to not drop requests coming from host OS
  • Run bundle exec rspec to run the tests (RSpec is a test framework for Ruby)
  • Write code to get the failing test to pass.

4) Commit and push

  • When the tests pass on your local machine, push your changes to GitHub.
  • GitHub Actions workflows will run. You can check their state using the Actions tab on the repo website.

5) Check your inbox / issues

  • You will be notified of problems or new work items via GitHub issues on your repository.
  • While you wait, see where you could refactor your code, read the tutorial, or explore the project files.

6) For each issue

  • Write a new test that documents the missing or failing behavior.
  • Commit the failing test and reference the issue.
    • The commit message could be Failing test for #<ISSUE NUMBER>.
    • There is no need to push the failing commit.
  • Fix the issue and make your test pass. Then commit the changes.
    • While an issue is open, the exercise will try to create comments on the issue, notifying you of errors.

7) Repeat steps 4 to 6 until the exercise is complete.

Tips

  • The main goal of this exercise is to learn the basics of Ruby on Rails. Don't hesitate to ask the teaching team or your fellow students for help!
  • The beginning of this exercise is based on the official Getting Started with Rails Guide. When stuck, this should be your first read.
  • rails s starts the development server (by default on http://localhost:3000) so you can try out your app in the browser.
  • rails routes shows all available routes of the application.
  • For help with RSpec matchers, there is a Cheat Sheet or the documentation
  • Run rspec spec/<path_to_spec>.rb to only run tests within a single file.
  • Have a look at /spec/factories to get inspiration for your data model.
  • Besides generators and scaffolds, associations and validations are needed.
  • rails db:drop && rails db:migrate deletes the database and recreates it. This might be helpful for error recovery.
  • Make sure that all local changes are committed (git status) and pushed to the upstream repository (i.e., the one on GitHub) before the deadline.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.