Created
January 25, 2019 08:42
-
-
Save katafrakt/50e3870f8a73e85ca56011458d1099d2 to your computer and use it in GitHub Desktop.
Problem with flash in Hanami
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/inline' | |
gemfile do | |
gem 'hanami', '~> 1.3' | |
end | |
require 'hanami/action/session' | |
module Home | |
class Index | |
include Hanami::Action | |
include Hanami::Action::Session | |
def call(_params) | |
flash[:errors] = 'WRONG!' | |
puts "In index" | |
p flash | |
redirect_to '/redirected' | |
end | |
end | |
class Redirected | |
include Hanami::Action | |
include Hanami::Action::Session | |
def call(_params) | |
puts "In redirected" | |
p flash | |
self.body = flash[:errors] | |
end | |
end | |
end | |
module FlashApp | |
class Application | |
attr_reader :routes | |
def initialize | |
@routes = Hanami::Router.new do | |
get '/', to: 'home#index' | |
get '/redirected', to: 'home#redirected' | |
end | |
end | |
end | |
end | |
app = Rack::Builder.new do | |
use Rack::Session::Cookie, secret: SecureRandom.hex(16) | |
run FlashApp::Application.new.routes | |
end | |
Rack::Server.start app: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -L localhost:8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: