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

Slim Ruby on Rails: Controllers & Middlewares

Slim Ruby on Rails: Controllers & Middlewares

Krzysztof Wawer

June 21, 2017
Tweet

More Decks by Krzysztof Wawer

Other Decks in Programming

Transcript

  1. Slim Ruby on Rails:
    Controllers & Middlewares
    Krzysztof Wawer

    View full-size slide

  2. Request
    https://medium.com/@christemple/what-is-rack-in-ruby-7e0615f1d9b6

    View full-size slide

  3. Request
    Rack App
    Middlewares
    log auth cache
    HTTP Request
    HTTP Response

    View full-size slide

  4. Rack Middleware
    http://railscasts.com/episodes/151-rack-middleware

    View full-size slide

  5. Ruby on Rails
    Middleware stack
    $ rails new app
    $ rails new app --api
    $ rake middleware
    http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack

    View full-size slide

  6. Ruby on Rails
    Middleware stack
    use Rack::MethodOverride
    use Sprockets::Rails::QuietAssets
    use WebConsole::Middleware
    use ActionDispatch::Cookies
    use ActionDispatch::Session::CookieStore
    use ActionDispatch::Flash
    http://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack

    View full-size slide

  7. RoR Middlewares
    problem
    https://github.com/rails/rails/blob/master/railties/lib/rails/application/default_middleware_stack.rb

    View full-size slide

  8. http://paulserraino.com/rails/2016/02/29/rails-mountable-engines.html
    Rails Engines

    View full-size slide

  9. Ruby on Rails Engine
    http://tech.taskrabbit.com/blog/2014/02/11/rails-4-engines/

    View full-size slide

  10. ActionController::Base
    http://api.rubyonrails.org/classes/ActionController/Base.html

    View full-size slide

  11. ActionController::API
    http://api.rubyonrails.org/classes/ActionController/API.html

    View full-size slide

  12. ActionController::Metal
    http://api.rubyonrails.org/classes/ActionController/Metal.html

    View full-size slide

  13. ActionController::API
    http://api.rubyonrails.org/classes/ActionController/API.html

    View full-size slide

  14. • Strong Parameters
    • Params Wrapper

    View full-size slide

  15. • Strong Parameters
    • Params Wrapper
    Mapping

    View full-size slide

  16. Mapping - missing part
    Nested Attributes - revealing
    structure

    View full-size slide