views:

19

answers:

1

If both ProductsController and CategoriesController both inherit from GenericController, what is a good way to get the string products in the base class when the URL is pointing to the Products controller? (in this case, the base class's index action is doing things that would need to use the string products to query the database)

self.class.to_s can be used, and it is Analytics::ProductsController, or params[:controller] can be used and it is analytics/products, so both can be used to extract the sub-class's name. Is using one better than the other, or is a third way even better?

+1  A: 

Try

controller_name

Refer to the documentation for more details.

KandadaBoggu