Module Madness
Joshua Schairbaum
joshua.schairbaum at gmail.com
Tue May 8 12:42:55 EDT 2007
I was wrong. A symbol didn't work, it just didn't throw an error.
>From the code below, can anyone see why I wouldn't be able to
namespace a Global::Helpers module and include it in MyApp::Helpers
and have the methods available?
This seems to be the way that Camping::BasicAuth works, are
views/helpers different?
---------- Forwarded message ----------
From: Joshua Schairbaum <joshua.schairbaum at gmail.com>
Date: May 7, 2007 2:31 PM
Subject: Module Madness
To: camping-list at rubyforge.org
I'm wanted to make a "global" module that I could include in my
application for some shared code between them. I've been making
several camping apps and wanted them all to share a helper/partial
that contained the navigation.
I ran into a lot of difficulty when trying to include it, the primary
problem being "methodUndefined" errors. I did finally get it to work,
but I'm not sure why. Here's the relevant bits:
my_app.rb
MyApp::Helpers
include Global::Helpers
def month_name
...helper code
end
end
MyApp::Views
def layout
...some markaby
:navigation #throws an UndefinedMethod error if not a symbol
...some more markaby
end
end
global.rb
module Global
module Helpers
def navigation
...what i need
end
end
end
If I list the instance methods in irb, both "navigation" and
"month_name" shows up. However, I have to use use :navigation as a
symbol in my view as opposed to just using month_name for the other.
Both are defined as instance methods.
What gives with the symbol usage?
More information about the Camping-list
mailing list