Slide 1

Slide 1 text

RUBY ON RAILS UP AND RUNNING

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

WHY RUBY ON RAILS?

Slide 4

Slide 4 text

RUBY (IT’S THE LANGUAGE BEHIND RAILS) ELEGANT SIMPLE INTUITIVE BEAUTIFUL

Slide 5

Slide 5 text

RAILS (IT’S THE FRAMEWORK) CONVENTION OVER CONFIGURATION DON’T REPEAT YOURSELF PROGRAMMER HAPPINESS COMMUNITY

Slide 6

Slide 6 text

RUBY + RAILS = —

Slide 7

Slide 7 text

“Ruby on Rails is astounding. Using it is like watching a kung-fu movie, where a dozen bad-ass frameworks prepare to beat up the little newcomer only to be handed their asses in a variety of imaginative ways.” Nathan Torkington, O’Reilly Media

Slide 8

Slide 8 text

MVC (It’s the pattern behind Rails) Model View Controller

Slide 9

Slide 9 text

Model Generally, the nouns in your application responsible for behavior and data. posts, users, comments

Slide 10

Slide 10 text

View Displays information passed to it to the end user. Can be HTML, JSON, XML ...

Slide 11

Slide 11 text

Controller Directs or “controls” an applications flow. The glue that brings models and views together.

Slide 12

Slide 12 text

Browser View Controller Model

Slide 13

Slide 13 text

4 MAIN CONCEPTS

Slide 14

Slide 14 text

id title body 1 a blog post part I lorem ipsum... 2 a blog post part II lorem ipsum... 3 a blog post part III lorem ipsum... Active Record Database tables map to Ruby objects and columns become instance variables with getter and setter methods. class Post < ActiveRecord::Base end @post = Post.find(1) puts @post.title a blog post part I posts table

Slide 15

Slide 15 text

Action View Handles template rendering. Can use various template languages but Rails comes standard with ERB which is just Ruby mixed into HTML.
    <% @posts.each do |post| %>
  • <%= post.title %>
  • <% end %>
• a blog post part I • a blog post part II • a blog post part III posts.html.erb as seen in the browser

Slide 16

Slide 16 text

Action Controller Made up of various actions that are executed upon a request. Responsible for responding or directing web requests through an application. Typically requests data from a model and responds with a view. class PostsController < ApplicationController def index @posts = Post.all end end Gets all posts and renders the posts/index.html.erb view. How does it know?!

Slide 17

Slide 17 text

1 LAST MAIN CONCEPT BUT LET’S TALK ABOUT REST FIRST

Slide 18

Slide 18 text

REST Convention for working with resources over HTTP. GET PUT POST DELETE GET /posts => Returns all posts, usually maps to an index action GET /posts/123, usually maps to a show action => Returns a post with the ID of 123

Slide 19

Slide 19 text

Routes Connects URL paths to controller actions. Blog::Application.routes.draw do match "/posts" => "posts#index" resources :posts end

Slide 20

Slide 20 text

Browser ActionView ActionController ActiveRecord Routes

Slide 21

Slide 21 text

A FEW OTHER CONCEPTS

Slide 22

Slide 22 text

Ruby Gem A packaged Ruby library or application. You can install Ruby Gems using the RubyGems CLI tool like or you may use... gem install rails

Slide 23

Slide 23 text

Bundler Dependency management for your application’s Ruby Gems. source 'https://rubygems.org' gem 'rails', '3.2.3'

Slide 24

Slide 24 text

Rake Command line tool to script common tasks. For instance, migrating the database or running an application’s test suite. rake db:migrate rake test:unit

Slide 25

Slide 25 text

RVM Ruby Version Manager allows you to easily install, manage, and work with multiple ruby environments. Not necessary but very handy.

Slide 26

Slide 26 text

Git Has nothing to do with Ruby per se, but it is the de facto tool used to keep track of code. Git is a distributed version control system.

Slide 27

Slide 27 text

Rails Resources railscasts.com guides.rubyonrails.org railsforzombies.com peepcode.com rubygems.org ruby-toolbox.com

Slide 28

Slide 28 text

NOW LET’S DO STUFF!