Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: Get current namespace?

using a method :layout_for_namespace I set my app's layout depending on whether I am in frontend or backend, as the backend is using an namespace "admin".

I could not find a pretty way to find out which namespace I am, the only way I found is by parsing the string from params[:controller]. Of course that's easy, seems to be fail-safe and working good. But I am just wondering if there's a better, prepared, way to do this. Does anyone know?

Currently I am just using the following method:

def is_backend_namespace?   params[:controller].index("admin/") == 0 end 

Thanks in advance

Arne

like image 909
arnekolja Avatar asked Nov 19 '10 15:11

arnekolja


1 Answers

You can use:

self.class.parent == Admin 
like image 189
William Wong Garay Avatar answered Sep 23 '22 08:09

William Wong Garay