1

In runtime we can get the current controller and current action names by controller_name and action_name methods like wise,

I want to get all the remaining controllers and action names and models too if possible..

Any rails method available to get all the controller names and the action names in application controller.

1 Answer 1

0
@table_names =  ActiveRecord::Base.connection.tables
    @model_names = Array.new
    @model_names.each do |table_to_model|
      @model_names = @model_names.insert(@model_names.length,table_to_model.camelize.singularize) unless table_to_model.blank?
    end

This is how you get all Model name

2
  • Thanks alot ..By this way is it possible to get controller names and action and method names ... Thanks in Advance.. Regards, Ramanaa Selvaa
    – Ramanavel
    Aug 7, 2010 at 6:13
  • There's a typo in sachin7036's answer. The 3rd line should read "@table_names.each do |table_to_model|". You can get the controller name for a model by doing something like... kontroller = eval("#{model_name.camelcase<<'Controller'}") You can get the action names (in 2.3.8 or lower) by doing something like... actions = kontroller.action_methods
    – worktheweb
    Feb 10, 2012 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.