我想使用自定义通知帮助程序在我的Padrino应用程序中生成通知(flash)消息。在助手里面我想使用内置的Padrino助手(flash和content_tag。(见下面的例子)
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
但如果我在我的视图中使用帮助器,则会出现以下错误: “NoMethodError - Notification方法`content_tag'用于NotificationHelper:Class:”
我错了什么?
答案 0 :(得分:2)
也许您应该在帮助者之后正确注册:
module Flash
def notify # without self
end
end
class MyApp < Padrino::Application
# ...
# after helpers
helpers Flash
end
看看:https://github.com/padrino/padrino-contrib/blob/master/lib/padrino-contrib/helpers/flash.rb