0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails middleware

Last updated at Posted at 2016-07-26

app.middleware.insert(0, Rack::MiniProfiler)
   class FooMiddleware
        def initialize(app)
            puts "init foo"
            @app = app
        end

        def call(env)
            puts "foo"
            result = @app.call(env)
            puts "finish foo"
            return result
        end
    end

    class BarMiddleware
        def initialize(app)
            puts "init bar"
            @app = app
        end

        def call(env)
            puts "bar"
            result = @app.call(env)
            puts "finish bar"
            return result
        end
    end

    class BazMiddleware
        def initialize(app)
            puts "init baz"
            @app = app
        end

        def call(env)
            puts "baz"
            result = @app.call(env)
            puts "finish baz"
            return result
        end
    end

    config.middleware.use FooMiddleware

    config.middleware.use BarMiddleware

    config.middleware.use BazMiddleware
foo
bar
baz
finish baz
finish bar
finish foo
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?