Best Rails Book You've Never Read

Best Rails Book You've Never Read

A presentation on all the benefits you gain after reading Rebuilding Rails by Noah Gibbs.

5f81e2d2889d7642fd84c8b24db7ee17?s=128

DamirSvrtan

June 23, 2016
Tweet

Transcript

  1. The best Rails book you’ve never read. DAMIR SVRTAN

  2. 01 RUBY/RAILS BOOKS

  3. WELL KNOWN BOOKS POODR Sandi Metz RoR Tutorial Michael Hartl

    Pickaxe David Thomas Metaprogramming Ruby Paolo Perrotta
  4. and many more..

  5. 02 REBUILDING RAILS

  6. None
  7. NOAH GIBBS

  8. Get your hands dirty and build your own Ruby Web

    Framework - NOAH GIBBS
  9. RAILS INTERNALS CAN TEACH YOU A LOT…

  10. NOT JUST READING - ALSO LOTS OF CODING

  11. BUILD YOUR OWN GEM bundler new my_framework

  12. PUBLISH YOUR FIRST GEM push it to rubygems.org

  13. LEARN HOW RACK WORKS what is Rack?

  14. Browser App Server RACK Ruby App

  15. ALMOST EVERY RUBY FRAMEWORK USES IT! Rails, Sinatra, Hanami, Roda..

  16. # config.ru require 'rack' class MyApp def call(env) [200, {

    'Content-Type' => 'text/html' }, ["Hello World"]] end end run MyApp.new
  17. run object.call

  18. run proc { |env| [200, { 'Content-Type' => 'text/html' },

    [Time.now] }
  19. # config.ru require 'rack' class MyApp def call(env) [200, {

    'Content-Type' => 'text/html' }, ["Hello World"]] end end run MyApp.new
  20. env argument

  21. { "SERVER_SOFTWARE"=>"THIN 1.6.3 CODENAME PROTEIN POWDER", "SERVER_NAME"=>"LOCALHOST", "RACK.INPUT"=>#<STRINGIO:0X007FFD50C4A9C8>, "RACK.VERSION"=>[1, 0],

    "RACK.ERRORS"=>#<IO:<STDERR→, "RACK.MULTITHREAD"=>FALSE, "RACK.MULTIPROCESS"=>FALSE, "RACK.RUN_ONCE"=>FALSE, "REQUEST_METHOD"=>"GET", "REQUEST_PATH"=>"/", "PATH_INFO"=>"/", "REQUEST_URI"=>"/", "HTTP_VERSION"=>"HTTP/1.1", "HTTP_HOST"=>"LOCALHOST:3000", "HTTP_CONNECTION"=>"KEEP-ALIVE", "HTTP_CACHE_CONTROL"=>"MAX-AGE=0", "HTTP_UPGRADE_INSECURE_REQUESTS"=>"1", "HTTP_USER_AGENT"=>"MOZILLA/5.0 (MACINTOSH; INTEL MAC OS X 10_11_3) APPLEWEBKIT/537.36 (KH™L, LIKE GECKO) CHROME/51.0.2704.103 SAFARI/537.36", "HTTP_ACCEPT"=>"TEXT/H™L,APPLICATION/XH™L+XML,APPLICATION/XML;Q=0.9,IMAGE/WEBP,*/*;Q=0.8", "HTTP_ACCEPT_ENCODING"=>"GZIP, DEFLATE, SDCH", "HTTP_ACCEPT_LANGUAGE"=>"EN-US,EN;Q=0.8", "HTTP_COOKIE"=> "", "GATEWAY_INTERFACE"=>"CGI/1.2", "SERVER_PORT"=>"3000", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "RACK.URL_SCHEME"=>"HTTP", "SCRIPT_NAME"=>"", "REMOTE_ADDR"=>"127.0.0.1" }
  22. # config.ru require 'rack' class MyApp def call(env) [200, {

    'Content-Type' => 'text/html' }, ["Hello World"]] end end run MyApp.new
  23. [200, { 'Content-Type' => 'text/html' }, ["Hello World”]]

  24. use Rack::Session::Cookie, :secret => 'abc123' use BetterErrors::Middleware if Noodles.env.development? use

    Rack::CommonLogger, $stdout use Rack::ContentType use Rack::MethodOverride use Rack::Static, urls: ["/css", "/images", "/js", "/favicon.ico"], root: "public" run Noodles.application
  25. BUILD YOUR OWN ROUTER

  26. Noodles.http_app.routes do root_to 'home#index' get 'chat', 'chat#index' get "auth/:provider/callback", 'session#success'

    get "auth/failure", 'session#failure' post "rooms", "rooms#create" delete "logout", 'session#logout' resources :users end
  27. BUILD YOUR OWN CONTROLLERS

  28. class RoomsController < BaseController def create room = Room.new(name: params['name'],

    public: true) room.save! redirect_to ‘/' end end
  29. HOW TO LOAD CONTROLLERS?

  30. HOW TO LOAD RAILS CONTROLLERS? Rails magic autoloading

  31. require ‘users_controller’

  32. $LOAD_PATH

  33. puts $LOAD_PATH [ "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.7/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/daemons-1.1.9/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/slop-3.6.0/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/method_source-0.8.2/lib",

    "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pry-0.10.3/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/coderay-1.1.1/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/pry-byebug-3.3.0/lib", "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/byebug-8.2.4/lib" ]
  34. puts $LOAD_PATH [ "/Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0/lib" ] ls /Users/damirsvrtan/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0/lib/did_you_mean core_ext formatter.rb spell_checkable.rb

    version.rb extra_features jaro_winkler.rb spell_checkers extra_features.rb levenshtein.rb verbose_formatter.rb require 'did_you_mean/extra_features'
  35. None
  36. controllers_folder_path = File.join("app", "controllers") $LOAD_PATH << controllers_folder_path

  37. method_missing?

  38. const_missing?

  39. class Object def self.const_missing(constant) require Noodles.to_underscore(constant.to_s) Object.const_get(constant) end end Admin::UsersController

    -> admin/users_controller
  40. Learn how redirects work (30× status)

  41. Learn how render and ERB work (use haml, slim, tilt)

  42. Learn how cookies work

  43. class UsersController < ApplicationController def index cookies[:favorite_color] ||= :black end

    end
  44. class UsersController < ApplicationController def index unless request.cookies[:favorite_color] == :black

    response.headers.push('Set-Cookie', 'favorite_color=black') end end end
  45. Build your own small ORM

  46. 03 BENEFITS

  47. REINVENTING THE WHEEL

  48. BETTER GRASP ON RAILS, RACK, GEMS & THE HTTP LAYER

  49. None
  50. Any questions? DAMIR.SVRTAN@INFINUM.CO @DAMIRSVRTAN Visit infinum.co or find us on

    social networks: infinum.co infinumco infinumco infinum