Ruby On Rails, Design, Simplicity, Web 2.0, Ajax, Mac and Tons of Pizza.

Feb 08

Howto: List the actions inside a controller

Posted by Sandro Paganotti in Ruby on Rails - comments are closed digg this add to delicious

One of the most greatest Ruby feature is reflection; it let you inspect your classes and retrive informations about them. For example if you need to know the name of all the actions inside a controller you can just wrote this line:


MyController.instance_methods(false) 

And… if you are curious, dump the array returned from


MyController.methods

You will find a lot of useful methods !

Sandro.

Comments

  • Marcio

    Posted on February 09

    Just use MyController.instance_methods(false) and to list just the public methods MyController.public_instance_methods(false)
  • Sandro Paganotti

    Posted on February 09

    Thank you Marcio, i'll update the post according to your suggest. Sandro
  • John

    Posted on February 09

    Special thanks to Marcio for right comment, and to Sandro Paganotti for the rest! :)
  • Alex

    Posted on February 11

    Thanks! This is something what I always needed =)

Post a comment

Categories:

Tags:

Powered by Mephisto, Valid XHTML 1.1, Valid CSS - Supported by Wave Factory