# Styles for tabnav plugin

**URL:** <https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864>\
**Category:** Rails\
**Created:** [March 6, 2007, 2:46pm UTC](https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864 "2007-03-06T14:46:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [March 6, 2007, 2:46pm UTC](https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864/1 "2007-03-06T14:46:38Z")

</div>

Hi all,

I’m using the tabnav plugin for a community project and I think it is  
quite comfortable to use.

But, when I have many tabbed screens in my app, I have to generate many  
corresponding xyz\_tabnav.rb models. Now for each of these models there  
seems to be one template xyz\_tybnav.rhtml which contains the style for  
the corresponding tabnav.

In my app ALL tabbed screens will have the SAME style (as I would assume  
for most apps in general). Does it mean that I have to maintain many of  
these style files for all the tabbed screens redundantly?

Or can I consolidate the one style for all tabbed screens?

Cheers,

Star

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [March 6, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864/2 "2007-03-06T16:17:25Z")

</div>

I modified the ‘def tabnav tabnav\_sym method’ from tabnav’s  
application\_helper\_extension.rb to check the tabnav\_sym to determine  
the object being rendered. Based on that information, I select the  
partial to use for the rendering. I do a bit of code in the  
application.rhtml layout using @first\_render or getting the controller  
name directly to select the tabnav to display and pass that to the  
start tabnav tag.

I now have two partials (two nested tab styles) that replace what  
would have been over 15 tabnav partials for my application. I don’t  
know if this will work with the newer versions, but it solved my  
problem.

Example with a nested tabnav:

app/views/layouts/application.rhtml:

\<%= render\_partial ‘common/header’ -%\>

\<%= start\_tabnav :main -%\>  
\<%  
case @first\_render  
when /^admin/  
tabnav\_set = :admin  
when /^home/  
tabnav\_set = :home  
end %\>  
\<%= start\_tabnav tabnav\_set -%\>  
  
\<%= yield -%\>  
\<%= end\_tabnav -%\>  
  
\<%= end\_tabnav -%\>

\<%= render\_partial ‘common/footer’ -%\>

tabnav application\_helper.rb:

# Selects the correct template to use for rendering the selected

# tabnav object.

def tabnav tabnav\_sym  
# Set the name of the template  
if tabnav\_sym.id2name == ‘main’  
tabnav\_template = ‘main’  
else  
tabnav\_template = ‘secondary’  
end

```
# Render the tabnav partial
result = capture do
  render :partial => "tabnav/#{tabnav_template}_tabnav",
         :locals => { :tabs => tabnav_sym.to_tabnav.tabs }
end
result

```

end

On Mar 6, 6:46 am, Star B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [March 6, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864/3 "2007-03-06T17:28:32Z")

</div>

Sounds good.

Another solution could be to change the tabnav renderer in a way that  
not the tabnav class name is used to generate the style name but that a  
style name could be set via a method “set\_style” in the tabnav class  
definition (like “add\_tab”).

KRD wrote:

> I modified the ‘def tabnav tabnav\_sym method’ from tabnav’s  
> application\_helper\_extension.rb to check the tabnav\_sym to determine  
> the object being rendered. Based on that information, I select the  
> partial to use for the rendering. I do a bit of code in the  
> application.rhtml layout using @first\_render or getting the controller  
> name directly to select the tabnav to display and pass that to the  
> start tabnav tag.

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [March 20, 2007, 8:22am UTC](https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864/4 "2007-03-20T08:22:33Z")

</div>

Paolo D. wrote:

> You can specify the Tabnav’s class prefix with:
> 
> class BasicTabnav \< Tabnav::Base  
> html\_options :class =\> ‘inner\_tabnav’
> 
> ```
> add_tab
> ...
> end
> 
> ```
> 
> end
> 
> This overrides the default class naming, so you can share the same style  
> for every Tabnav. Then I’d remove the partials and move my CSS code  
> inside the main .css file.

Thanks! That was the only thing missing…

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [March 16, 2007, 2:39pm UTC](https://www.ruby-forum.com/t/styles-for-tabnav-plugin/87864/5 "2007-03-16T14:39:12Z")

</div>

You can specify the Tabnav’s class prefix with:

class BasicTabnav \< Tabnav::Base  
html\_options :class =\> ‘inner\_tabnav’

```
add_tab
  ...
end

```

end

This overrides the default class naming, so you can share the same style  
for every Tabnav. Then I’d remove the partials and move my CSS code  
inside the main .css file.
