I’m trying to write a module to be used as a mix-in, my first attempt at
such. This sample code outlines the basics of what I’ve done so far…
/lib/foo.rb:
require ‘foo/base’
module Foo
include FooBase
end
/lib/foo/base.rb:
module Foo
module FooBase
def foo_var
123
end
end
end
/app/controllers/application.rb
Filters added to this controller apply to all controllers in the
application.
Likewise, all the methods added will be available for all controllers.
require ‘foo’
class ApplicationController < ActionController::Base
include Foo
end
Given these three files, I can use “foo_var” without error in any of my
controllers. However, when I try to use “foo_var” in a view, I get a “no
method” error. I know it’s possible to make “foo_var” available
everywhere - example, the login engine had “current_user” and “user?”
methods that could be accessed in any controller or view.
I’m sort of shooting in the dim light, not quite the dark, after reading
some articles and sample code. Any help appreciated.
thanks.