Hi, what variable can I access to get the current action or controller? (specifically in a view)
| SitePoint Sponsor |



Hi, what variable can I access to get the current action or controller? (specifically in a view)



Sorry to double post but I found a [shaky?] solution which I am using now.
Basically the reason for this is because I didn't want to have the sidebar login box visible when on the actual log in page... so I did this in the sidebar in the view:
So if the current url (found by calling url_for with no params) equals the url for the login action in the user controller, then dont show it.Code:<% if @in_user.nil? and url_for() != url_for(:action => 'login', :controller => 'user') then %> Show log in form... <% elsif !@in_user.nil? %> We're in! <% end %>
It works for now![]()


controller.controller_name and controller.action_name
Studio Rockstar's Blog - A journey to quitting the dayjob.



Thanks! It worked like a charm! Now that is what i was looking forOriginally Posted by Brak
![]()



Sorry to dig up this topic but there is also a helper to figure out if you're on the page specified, you just do:
Code:<% if current_page?(:controller => 'bla', :action => 'foo') then %> ... <% end %>![]()





I took a peek at the code for that helper because I was curious how it worked.
Ha! That's compact.Code:237: def current_page?(options) 238: url_for(options) == @controller.request.request_uri 239: end
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
Bookmarks