Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension adding flash bag functionality #15

Merged
merged 2 commits into from
Jul 25, 2019
Merged

Conversation

waiting-for-dev
Copy link
Owner

Add extension adding flash bag functionality

require 'web_pipe'
require 'rack/session/cookie'
require 'rack-flash'

WebPipe.load_extensions(:flash)

class MyApp
  include WebPipe

  use :session, Rack::Session::Cookie, secret: 'secret'
  use :flash, Rack::Flash

  plug :put_in_flash, ->(conn) { conn.put_flash(:notice, 'Hello world') }
  plug :put_in_flash_now, ->(conn) { conn.put_flash_now(:notice_now, 'Hello world now') }
end

For this extension to be used, Rack::Flash middleware must be added to
the stack (gem name is rack-flash3. This middleware in turns depend on
Rack::Session middleware.

When response headers or body was not set, the default was a frozen
instance. Consequently, middlewares were unable to modify it using
conventional destructive methods. For example, `rack-session` was unable
to add `SET-COOKIE` header because it uses `Hash#[]`.
```ruby
require 'web_pipe'
require 'rack/session/cookie'
require 'rack-flash'

WebPipe.load_extensions(:flash)

class MyApp
  include WebPipe

  use :session, Rack::Session::Cookie, secret: 'secret'
  use :flash, Rack::Flash

  plug :put_in_flash, ->(conn) { conn.put_flash(:notice, 'Hello world') }
  plug :put_in_flash_now, ->(conn) { conn.put_flash_now(:notice_now, 'Hello world now') }
end
```

For this extension to be used, `Rack::Flash` middleware must be added to
the stack (gem name is `rack-flash3`. This middleware in turns depend on
`Rack::Session` middleware.
@waiting-for-dev waiting-for-dev added the enhancement New feature or request label Jul 25, 2019
@waiting-for-dev waiting-for-dev merged commit d4d52cb into master Jul 25, 2019
@waiting-for-dev waiting-for-dev deleted the flash branch July 26, 2019 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant