[typo] Looking for a better way to do this...

Kyle Heon kheon at comcast.net
Thu Sep 29 20:24:08 EDT 2005


I'm starting to learn Ruby so I apologize for this hackish code.

I have this method in my articles_helper file:

def navigation_tab(tab)
  if tab == nil && @controller.action_name.eql?('index')
    "activeTab"
  elsif tab != nil && @controller.params['name'].to_s.eql?(tab.to_s)
    "activeTab"
  elsif @controller.controller_name.eql?('articles') && (
@controller.action_name.eql?('category') ||
@controller.action_name.eql?('permalink') ||
@controller.action_name.eql?('search') ) && tab == nil
    "activeTab"
  else
	"Tab"
  end
End

It can be passed one of three values:

nil
photography
About

The function of this method is to set one of three navigational tabs to a
selected state based on the currently active controller/action.

I know there must be a better way. I particularly don't care for the
multiple elsif statements.

Kyle Heon
kheon at comcast.net



More information about the Typo-list mailing list