Topic: How do I know which controller I'm in?
I have an rhtml file that is used by two controllers, how do I determine which controller is currently rendering the file?
You are not logged in. Please login or register.
Rails Forum - Ruby on Rails Help and Discussion Forum » Controllers and Views » How do I know which controller I'm in?
I have an rhtml file that is used by two controllers, how do I determine which controller is currently rendering the file?
in your controller:
@current_controller = controller_name
#and i dont mean, write the controller name.. "controller_name" is a function built into rails.
#cheers
if @current_controller == 'controller1'
#do something
else #other controller.
#do something else
end
Last edited by pjleonhardt (2006-10-15 01:10:11)
There's also params[:controller]
How about identifying the (child?) controller in this instance?
eg http://localhost:3000/items/list
controllers/items_controller.rb:
class ItemsController < AdminController
end
class AdminController < ApplicationController
def list
case controller_name # << how to get this to say "items" not "admin"
when "items"
...
end
end
end
Last edited by zubin8or (2006-11-09 05:21:53)
I'm not certain I understand. How is the admin controller related to the Items controller?
Edit: Oy, didn't notice ItemsController was a subclass of AdminController. Nevermind.
Last edited by ryanb (2006-11-09 18:25:21)
Hosting provided by aTech Media