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

Justin Palmer typo at isolated-designs.net
Fri Sep 30 22:05:14 EDT 2005


Check out the way we do it in Typo's admin:

   def tab(label, options = {})
     if controller.controller_name =~ /#{options[:controller].split 
('/').last}/
       content_tag :li, link_to(label, options, {"class"=>  
"active"}), {"class"=> "active"}
     else
       content_tag :li, link_to(label, options)
     end
   end

You can see this implemented in the admin layout.

Cheers,
   -Justin


On Sep 29, 2005, at 7:24 PM, Kyle Heon wrote:

> 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
>
> _______________________________________________
> Typo-list mailing list
> Typo-list at rubyforge.org
> http://rubyforge.org/mailman/listinfo/typo-list
>
>
>



More information about the Typo-list mailing list