Controller methods


I want to be a little clever with my views and basically inspect a
controller to autodiscover it’s methods and then create a link for each

Now I’ve given a try to, but I get a problem
with the dependency on ApplicationController (in the console), is there
a way to do this? I assume there is a way to do this.

What I want is

def available
@available = ReportsController.actions - [:index, :list]

or something similar


There are two methods that do what you’re looking for.

Object.methods returns a list of all the class methods,
Module.instance_methods returns a list of all the instance methods.

What you’re looking for are the instance methods of your controller,
without anything that belong to the superclass (ApplicationController).

As such, try this (you might be able to stick it in
ApplicationController and still work, haven’t actually tried it):

def actions

start with all my methods

self.class.instance_methods -
# remove my superclass’s methods
self.class.superclass.instance_methods -
# manually remove anything else I don’t want showing up

def non_action_methods

this method should be overridden by the concrete controllers,

and list anything you don’t want showing up.

Also good to list any methods of mixins, like a login generator

[‘index’, ‘list’]

Do note that the method names returned from non_action_methods should be
strings, not symbols.

  • Jamie