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

Flash in unsable #65

Closed
lessless opened this issue Dec 22, 2014 · 0 comments · Fixed by #63
Closed

Flash in unsable #65

lessless opened this issue Dec 22, 2014 · 0 comments · Fixed by #63
Milestone

Comments

@lessless
Copy link
Contributor

Hello! There is a problem with empty flash

NoMethodError: undefined method `[]' for nil:NilClass
    /Users/lessless/.gem/ruby/2.1.4/bundler/gems/controller-534fc0efe543/lib/lotus/action/flash.rb:103:in `data'
    /Users/lessless/.gem/ruby/2.1.4/bundler/gems/controller-534fc0efe543/lib/lotus/action/flash.rb:50:in `[]'
    /Users/lessless/tmp/lotusession/app/templates/application.html.erb:7:in `block (2 levels) in singleton class'
    /Users/lessless/tmp/lotusession/app/templates/application.html.erb:6:in `each'
    /Users/lessless/tmp/lotusession/app/templates/application.html.erb:6:in `block in singleton class'
    /Users/lessless/tmp/lotusession/app/templates/application.html.erb:-6:in `instance_eval'
    /Users/lessless/tmp/lotusession/app/templates/application.html.erb:-6:in `singleton class'
    /Users/lessless/tmp/lotusession/app/templates/application.html.erb:-8:in `__tilt_70348439917320'
require "lotus"

module App
  class Application < Lotus::Application
    configure do
      layout :application
      routes do
        get '/', to:      'home#index'
        get '/login', to: 'login#index'
      end
      sessions :cookie, secret: 'zzzzzzzzzzzzzzzzzzzzzz'
      controller.prepare do
        expose :flash
      end
      view.root Dir.pwd
    end

    load!
  end

  module Controllers::Home
    include Controller
    class Index
      include Action
      def call(params)
        # uncomment this line and everything will work
        # flash[:error] = "OMG"
      end
    end
  end

  module Controllers::Login
    include Controller
    class Index
      include Action

      def call(params)
        puts session.inspect
      end
    end
  end

  module App::Views::Home
    class Index
      include App::View
    end
  end

  module App::Views::Login
    class Index
      include App::View
    end
  end

  class App::Views::ApplicationLayout
    include Lotus::Layout
  end

end

run App::Application.new

here is the template

<!-- app/templates/application.html.erb --> 
<html>
  <head>
  </head>

    <div class="flash-messages">
      <% %i(error notice success).each do |type| %>
        <% if flash[type]  %>
          <div class="flash-message-<%= type %>"> <%= flash[type] %> </div>
        <% end %>
       <% end %>
    </div>


    <%= yield %>

  </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants