GT Web Developers - Rails Intro

011f777dae520e762d715840b903dc67?s=47 Mike Skalnik
October 02, 2012

GT Web Developers - Rails Intro

I was asked to give a brief overview of Rails & how it does MVC.

Students had already used Ruby & Sinatra and been exposed to some basic MVC subjects, but nothing too comprehensive. Next week they'd be diving more into code, and this was supposed to be a more high level overview

011f777dae520e762d715840b903dc67?s=128

Mike Skalnik

October 02, 2012
Tweet

Transcript

  1. Let talk Rails

  2. I’m Mike or @skalnik

  3. I work at GitHub

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

  5. Rails? Why

  6. Rails is a web framework

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

    need
  8. Rails makes life easy It does have a learning curve

    though. Once you get past it though, it lets you do stuff quick
  9.  ONE SEC! Before we go on…

  10. 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.
  11. $ gem install rails

  12. None
  13. None
  14. $ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!?

    Lets look into this…
  15. $ find . | wc -l $ cd my_billion_dollar_idea What’s

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

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

    $ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!? Lets look into this…
  18. None
  19. OH SHI— WTF HALP

  20. App is where our shit lives! And we got these

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

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

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

    models, views, and controllers directories in there…
  24. Lets generate some stuff before going forward. The exact command

    isn’t too important, but…
  25. Model contains business logic “Models your data” Responsible for behavior

    & data Usually database backed, but not always Lets check one out
  26. 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
  27. displays View information HTML, XML, JSON, etc Templated with things

    like ERB, Mustache, etc
  28. Under a pluralized model name directory Each folder is an

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

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

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

    “action” -> controller actions partials start with _ -> views you can render in other views
  32. handles the other two Controller

  33. 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?)
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. Assets: CSS, Javascript, Images Moved recently due to growing importance

  41. Config has a bunch of configuration (mind blowing, eh?) initializing

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

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

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

    settings, sets up the routes, database configuration
  45. 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
  46. Questions? Any

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