Slide 1

Slide 1 text

Ruby on Rails Yos Riady yosriady.com

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

goo.gl/waonpj

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Today’s Agenda ● Intro to Ruby (40 minutes) ● Rails (120 minutes) ● QA (20 minutes)

Slide 6

Slide 6 text

Introduction rubyonrails.org ruby-lang.org

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Built On Rails

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Ruby Language codecademy.com/en/tracks/ruby ● Variables ● Conditionals ● Loops + Iterators ● Blocks ● Data Structures ● Classes

Slide 11

Slide 11 text

Installing Rails https://lite.nitrous.io

Slide 12

Slide 12 text

Creating a New Rails Application rails new myapp cd myapp bundle install rails server

Slide 13

Slide 13 text

MVC Architecture

Slide 14

Slide 14 text

Building a Static Site rails generate controller Pages home Now try and visit ‘/pages/home’. What do you see?

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Building a Static Site Try adding a few more pages on your own. Remember, for each page: ● Add a new route in routes.rb ● Add a new action in PagesController.rb ● Add a view .erb file

Slide 17

Slide 17 text

Building a Static Site Try adding the following in your action: def home @now = Time.now end In your home.html.erb file, add: <%= @now %>

Slide 18

Slide 18 text

Building a Dynamic Site At the core, most database driven web sites are the same. They need to store records and provide a way to do the following: ● Create new records in the database ● Read or show the records in the database ● Update existing records ● Destroy or delete records Because these 4 actions are so common, Rails includes the scaffold command to make creating them easier. rails generate scaffold Confession title:string body:text

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

REST

Slide 22

Slide 22 text

Let’s add comments to our application! Users can create Comments for a Confession, and have it visible under the Confession entry. How do we do this? Building a Dynamic Site

Slide 23

Slide 23 text

What do we need? ● A new Comment model ● A new controller for Comments ○ A ‘create’ action to save new Comments to the DB ● A new route in routes.rb for ‘comments#create’ ● A view form for users to write a Comment Building a Dynamic Site

Slide 24

Slide 24 text

Building a Dynamic Site

Slide 25

Slide 25 text

Hands-On

Slide 26

Slide 26 text

Learning Resources ● http://tryruby.org/ ● http://guides.rubyonrails.org/ ● http://docs.railsbridge.org/intro-to-rails/ ● http://rails-4-0.railstutorial.org ● http://www.codecademy.com/learn/learn-rails

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Q&A Yos Riady yosriady.com

Slide 29

Slide 29 text

No content