SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Current Action/Controller

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

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    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 %>
    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.

    It works for now

  3. #3
    SitePoint Addict Brak's Avatar
    Join Date
    Jul 2004
    Location
    Central Coast, CA
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    controller.controller_name and controller.action_name
    Studio Rockstar's Blog - A journey to quitting the dayjob.

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Brak
    controller.controller_name and controller.action_name
    Thanks! It worked like a charm! Now that is what i was looking for

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 %>

  6. #6
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I took a peek at the code for that helper because I was curious how it worked.
    Code:
    237:       def current_page?(options)
    238:         url_for(options) == @controller.request.request_uri
    239:       end
    Ha! That's compact.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •