Something is wrong in my use of the view.. i think!?

Hello all :slight_smile:
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 :thinking:

I found something that fixes my issue, if i use the “namespace:” option when building the Router and specify actions using a string (rather than the class)… like so

...
    module MyWeb
      module Controllers
        module Root
          class Index
            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
        end
      end
    end

    Router = Hanami::Router.new(namespace: MyWeb::Controllers) do
      root to: 'root#index'
    end
...

I’d like to understand why it does not work as expected when using constants to specify the actions in the router