我尝试从 Module 类内部访问 URL 帮助程序。这是我的代码:
module Station
class Plugins
@@plugins = [] unless defined?(@@plugins) && @@plugins.class == Array
class << self
def all
return @@plugins.sort_by { |p| p[:weight] }
end
def register(plugin = {})
raise "plugin must be a Hash (ie.: `register(:foo => 'bar')`)" unless plugin.class == Hash
raise "plugin must contain :name (ie.: `register(:name => 'my_plugin')`)" unless plugin[:name].present?
plugin[:weight] = 1 unless plugin[:weight].present?
plugin[:href] = eval("#{plugin[:name].downcase.pluralize}_url") unless plugin[:href].present?
@@plugins.push(plugin) unless @@plugins.include?(plugin)
end
end
# include default plugins:
Station::Plugins.register(:name => "Pages", :weight => -1)
end
end
当我运行我的服务器时,我得到了这个错误:
undefined local variable or method `pages_url' for Station::Plugins:Class
我读了很多关于“如何从类中调用 url 助手”的内容,但我找到的解决方案都没有为我工作。