I try to access URL helper from inside a Module class. Here's my code :
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
When I run my server, I got this error back:
undefined local variable or method `pages_url' for Station::Plugins:Class
I read a lot about "how to call url helper from a Class", but none of the solutions I found worked for me.
Station
, so I changed my code to callstation.pages_url
, but i've got this error back :undefined local variable or method
station' for Station::Plugins:Class. I also tryied to call
my_app.pages_url` since the route i want to call appears inrake routes
but i got a similar error :undefined local variable or method
main_app' for Station::Plugins:Class`. Do I need to include something in my Module? – Extender