Hai cayce,
Once you include a module say Foo, only methods from Foo will be mixed
to the included class.
But i am not sure whether the nested module''s will also get mixed to
the included class. If yes, not sure how to access those methods.
But in your example if you add
require ''foobase''
class ApplicationController < ActionController::Base
include Foo
include FooBase
end
now if you say
ApplicationController.new.foo_var, surely it will work.
On Aug 28, 7:58 pm, Cayce Balara
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---