Understanding where certain 'inherited' methods come from in ActionController::Base

Hi I just started getting my hands on Rails, I've been reading a good
book on the subject but now I want to continue by myself and with the
help of the rails api documentation but I find it quite difficult to
follow (copared with the Java generated docs for example).

One thing that I still can't get to understand is how methods like
'layout' become available on my controllers to mention one example I
supposed that the method was defined inside ActionController::Base but
reading the docs I see there is no such thing defined there.

Can you please clarify on this issue, I believe it may be something
related to the Ruby that I still don't know about.

Thanks in advance.

Try apidock.com.


Hope it helps.

Ok thanks for the info, those docs seem more friendly, anyway, I still
don't understand where those methods (for ex. layout) get inherited or
injected don't know how that magic happens they aren't mentioned even
in apidock.com.


when in doubt, cd to one of your projects and e.g.
  find vendor/rails -type f -exec grep -H 'def layout' {} \;

You'll see exactly how the magic happens :slight_smile: (and in this case, also
lots o' comments).


Thanks again for the feedback, yep I already did a recursive grep
inside my gems dirs and found those definitions I guess there i'll
find the real info, anyway what I find confusing is that in the docs
those automatic inclusions are not mentioned, maybe those are obvious
or implicit and they can be derived from the module name I really
don't know because Im also new to the Ruby language.

Is it possible that because both ActionController::Base and
ActionController::Layout::ClassMethods share th 'ActionController'
module they are inside the same namespace and all public methods of
Layout are available to Base? Can I conclude that this is the case
with all clases inside ActionController?

Please excuse my enormouse ignorance on the subject
Thanks for you patience!

It might be easier to understand what's going on in Rails master. Take
a look at http://github.com/rails/rails/blob/master/actionpack/lib/action_controller/base.rb#L5-37.
As you can see, the Base class is including a series of modules. In
Ruby, modules are like dynamic superclasses; including one adds the
module to the superclass chain.

For instance, observe that ActionController::Base includes
ActionController::UrlFor. You can follow that module to
which has the much-used url_for method (http://github.com/rails/rails/

Hope this helps.

-- Yehuda

Thanks Yehuda that was of help.