Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GT Web Developers - Rails Intro

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

Mike Skalnik

October 02, 2012
Tweet

More Decks by Mike Skalnik

Other Decks in Education

Transcript

  1. Rails makes life easy It does have a learning curve

    though. Once you get past it though, it lets you do stuff quick
  2. 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.
  3. $ find . | wc -l $ cd my_billion_dollar_idea What’s

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

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

    $ cd my_billion_dollar_idea What’s that find thing do? 88 FILES!? Lets look into this…
  6. App is where our shit lives! And we got these

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

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

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

    models, views, and controllers directories in there…
  10. Model contains business logic “Models your data” Responsible for behavior

    & data Usually database backed, but not always Lets check one out
  11. 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
  12. Under a pluralized model name directory Each folder is an

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

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

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

    “action” -> controller actions partials start with _ -> views you can render in other views
  16. 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?)
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. Config has a bunch of configuration (mind blowing, eh?) initializing

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

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

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

    settings, sets up the routes, database configuration
  27. 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