SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Location
    Miami, Fl
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do i get the name of my methods in my view.

    Excuse the newbieness...

    I want to create a helper for displaying the name of the actions in my controller that you are in, but can seem to figure out how to do this. any help would be great! thanks!

  2. #2
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There isn't a way that I know of...
    I just created a new controller in the console and was scrolling through all of the defined methods (thats not to say that ActionController doesn't dynamically add methods are run time like ActiveRecord does, though) and didn't find any that would help..
    There is a ".methods" ".public_methods" and ".private_methods" but those return _all_ methods a controller has, not just those that you've defined.

    Best of Luck
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Location
    Miami, Fl
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well basically what im trying to do is i have in my view.

    <body id=<&#37;= I WANT THE METHOD NAME HERE %>

    so every page has a unique id on the body.

    thank you for your comments.. ill keep looking.. maybe it cant be done.

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you just want the name of the _current_ action:

    Code ruby:
      #in your view
      <body id="<%= params["action"] %>">

    Sorry for the confusion, the wording of your initial post lead me to believe you were trying to build a list of all your controller actions.
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also do:
    Code:
    <p>The controller name is <&#37;= self.controller.controller_name -%></p>

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    params[:action]

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry - I'm having a blonde moment:

    Code:
    <p>The controller name is <&#37;= self.controller.controller_name -%></p>
    <p>The action name is <%= self.controller.action_name -%></p>


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
  •