Ruby on Rails

A Tiny Introduction


Elizabeth Mitchell


February 2016

Girl Develop It Ann Arbor

What is Ruby on Rails?

Ruby on Rails is a web development framework that uses Ruby, a Model View Controller pattern (MVC), and lots of built in awesomeness to help developers build websites and apps.

Ruby Loves Objects

Ruby is an object-oriented programming language.

Rails Loves Objects

  • Each bit of data and each collection of data can be represented by an object.
  • Each object can have properties and methods.
  • We can interact with these data objects.

A collection of people is an object.

Each individual person is an object.

Accessing Data Objects

Find a person with an id of 1: p1 = Person.find(1)

Find out a person's name: p1.name

Interact with all the people: Person.all

Rails Allows Quick Access to Data

through the Rails Console

IRB is Awesome

In Intro to Ruby, you have likely interacted with IRB (the interactive Ruby shell).

Rails has a built-in shell called Rails Console based off of IRB.

Rails Console is Awesome

  • You can directly interact with data, add records to your database, and edit and delete records.
  • You can add/edit fake data during development.
  • Very helpful tool for a front-end developer.

How to access Rails Console

  1. Inside a terminal/console, navigate to a folder that is a Rails project.
    cd my-rails-project
  2. Type in your console rails console or rails c for short.
  3. Interact with data and do cool things.

Model View Controller (MVC) in Rails

V(iews)

Views

layouts/templates that define how to show content. They communicate with the controller, receiving variables and information that are used to display data.

C(ontrollers)

Controllers

are the glue between models and views. Hand off data from the model to the view. Take user input from the view and save those changes to the database by communicating with the model.

Routes

assign URLs to specfic controllers and their actions (methods within each controller). Example: my.app/people pulls up the People controller and the index action.

M(odel)

Active Record

communicates with the database. Responsible for business logic. Represents data objects as models. In charge of associations between models.

Models

define the structure of objects (through methods, properties).

MVC

Routes communicate with Controllers

Controllers communicate with Models

Controllers communicate with Views

Rails Views Are Awesome

  • Include minimal logic
  • Are resuable in different parts of the application.
  • Are modular. Each piece of page can be chunked out into components

Rails Is Awesome