Slide 1

Slide 1 text

Let talk Rails

Slide 2

Slide 2 text

I’m Mike or @skalnik

Slide 3

Slide 3 text

I work at GitHub

Slide 4

Slide 4 text

http://github.com/edu We :heart: Students Get a free Micro account!

Slide 5

Slide 5 text

Rails? Why

Slide 6

Slide 6 text

Rails is a web framework

Slide 7

Slide 7 text

a Rails is kitchen sink Tries to include everything you’d need

Slide 8

Slide 8 text

Rails makes life easy It does have a learning curve though. Once you get past it though, it lets you do stuff quick

Slide 9

Slide 9 text

 ONE SEC! Before we go on…

Slide 10

Slide 10 text

Linux Users Make sure to install sqlite3 libsqlite3-dev Rails uses SQLite for local dev, so make sure you have it. OS X comes with it. Rails Installer includes it.

Slide 11

Slide 11 text

$ gem install rails

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

$ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!? Lets look into this…

Slide 15

Slide 15 text

$ find . | wc -l $ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!? Lets look into this…

Slide 16

Slide 16 text

$ find . | wc -l 88 $ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!? Lets look into this…

Slide 17

Slide 17 text

$ find . | wc -l 88 $ open . $ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!? Lets look into this…

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

OH SHI— WTF HALP

Slide 20

Slide 20 text

App is where our shit lives! And we got these models, views, and controllers directories in there…

Slide 21

Slide 21 text

App is where our shit lives! And we got these models, views, and controllers directories in there…

Slide 22

Slide 22 text

App is where our shit lives! And we got these models, views, and controllers directories in there…

Slide 23

Slide 23 text

App is where our shit lives! And we got these models, views, and controllers directories in there…

Slide 24

Slide 24 text

Lets generate some stuff before going forward. The exact command isn’t too important, but…

Slide 25

Slide 25 text

Model contains business logic “Models your data” Responsible for behavior & data Usually database backed, but not always Lets check one out

Slide 26

Slide 26 text

class Post < ActiveRecord::Base belongs_to :author has_many :comments attr_accessible :title, :body end ActiveRecord? -> ORM & DSL We can define relationships! And whitelist attributes that can be updated

Slide 27

Slide 27 text

displays View information HTML, XML, JSON, etc Templated with things like ERB, Mustache, etc

Slide 28

Slide 28 text

Under a pluralized model name directory Each folder is an “action” -> controller actions partials start with _ -> views you can render in other views

Slide 29

Slide 29 text

Under a pluralized model name directory Each folder is an “action” -> controller actions partials start with _ -> views you can render in other views

Slide 30

Slide 30 text

Under a pluralized model name directory Each folder is an “action” -> controller actions partials start with _ -> views you can render in other views

Slide 31

Slide 31 text

Under a pluralized model name directory Each folder is an “action” -> controller actions partials start with _ -> views you can render in other views

Slide 32

Slide 32 text

handles the other two Controller

Slide 33

Slide 33 text

class PostsController < ApplicationController def index @posts = Post.all respond_to do |format| format.html format.json { render json: @posts } end end end Index action! We can see different kinds of responses (How are these communicated to Rails?)

Slide 34

Slide 34 text

Controller Browser View Model Browser sends request which controller sees Controller coordinates with Model Passes values to view View renders values and sends to browser

Slide 35

Slide 35 text

Controller Browser View Model Browser sends request which controller sees Controller coordinates with Model Passes values to view View renders values and sends to browser

Slide 36

Slide 36 text

Controller Browser View Model Browser sends request which controller sees Controller coordinates with Model Passes values to view View renders values and sends to browser

Slide 37

Slide 37 text

Controller Browser View Model Browser sends request which controller sees Controller coordinates with Model Passes values to view View renders values and sends to browser

Slide 38

Slide 38 text

Controller Browser View Model Browser sends request which controller sees Controller coordinates with Model Passes values to view View renders values and sends to browser

Slide 39

Slide 39 text

Controller Browser View Model Browser sends request which controller sees Controller coordinates with Model Passes values to view View renders values and sends to browser

Slide 40

Slide 40 text

Assets: CSS, Javascript, Images Moved recently due to growing importance

Slide 41

Slide 41 text

Config has a bunch of configuration (mind blowing, eh?) initializing settings, sets up the routes, database configuration

Slide 42

Slide 42 text

Config has a bunch of configuration (mind blowing, eh?) initializing settings, sets up the routes, database configuration

Slide 43

Slide 43 text

Config has a bunch of configuration (mind blowing, eh?) initializing settings, sets up the routes, database configuration

Slide 44

Slide 44 text

Config has a bunch of configuration (mind blowing, eh?) initializing settings, sets up the routes, database configuration

Slide 45

Slide 45 text

MyBillionDollarIdea::Application.routes.draw do resources :posts match 'admin' => 'admin#dashboard' end Rails tries to be “RESTful” -> give brief overview. Basically a set of standards for HTTP admin#dashboard?! -> Explain DSL, specifically AdminController Dashboard action

Slide 46

Slide 46 text

Questions? Any

Slide 47

Slide 47 text

Thanks! http://bit.ly/gt-rails-intro