How do I get an action’s controller name?
For example if I have an action called ‘show’, is there a way to get the name of the controller that this action ‘show’ belongs to?
e.g. show.controller_name
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, You need to know the MVC workflow of your application.
Secondly, you need to know that where in this MVC workflow are you wanting this controller name to be known for a particular action.
And third, then do:
Try this in a controller:
self.class.to_sThis will return the controller name for the request you made.
You can use filters in a controller to call this in turn to get the controller name.