Вопрос

i want to use a custom notification helper to generate notifications (flash) messages in my Padrino app. Inside the helper i want to use the built-in Padrino helpers (flash and content_tag. (See example below)

class NotificationHelper       

  def self.notify
    unless flash.empty?
      content_tag :div, class: 'notifications' do
        flash.map do |key, msg|
          headline = case key
          when :success then 'Super!'
          when :error   then 'Oh. Das tut uns leid.'
          end
          content_tag :p, :class => "notification" do
            content_tag(:span, headline, class: "headline #{key}") + msg
          end
        end.join("\n")
      end
    end
  end
end

But if i'm using the helper in my views, i got the following error: "NoMethodError - undefined method `content_tag' for NotificationHelper:Class:"

What did i wrong?

Это было полезно?

Решение

Probably you should register it correctly after helpers:

module Flash
  def notify # without self
  end
end

class MyApp < Padrino::Application
  # ...
  # after helpers
  helpers Flash
end

Take a look at: https://github.com/padrino/padrino-contrib/blob/master/lib/padrino-contrib/helpers/flash.rb

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top