Hello all
I am starting out using Hanami and the different gems. Happily using hanami-router and hanami-controller but ran into trouble when I got to using hanami-view (specially the session)… my problem is demoed in the config.ru
below.
It is behaving like the view is being rendered only once regardless of how many requests are made. On closer inspection it seems the session (within the view) is the bit that will not update once the view has been rendered.
Can you see anything I can do to the code below that will make the session behave?
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'hanami-router'
gem 'hanami-controller'
gem 'hanami-view'
end
require "hanami-router"
require "hanami-controller"
require 'hanami/action/session'
require "hanami-view"
IndexView = Class.new do
include Hanami::View
format :html
def render
puts "VCOUNTER: #{session[:counter]}"
return session[:counter].to_s
end
end
ControllerAction = Class.new do
include Hanami::Action
include Hanami::Action::Session
def call(params)
session[:counter] ||= 0
session[:counter] += 1
puts "CCounter: #{session[:counter]}"
self.body = IndexView.new(nil, exposures).render
end
end
Router = Hanami::Router.new do
root to: ControllerAction
end
app = Rack::Builder.new do
use Rack::Session::Cookie, secret: 'secret-string'
run Router
end
run app
When you make requests to the app above you will see “CCounter” increase as you’d expect, but “VCOUNTER” does not