# Css class as parameter

**URL:** <https://www.ruby-forum.com/t/css-class-as-parameter/140476>\
**Category:** Rails\
**Created:** [June 14, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/css-class-as-parameter/140476 "2008-06-14T19:13:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arte\_fact](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@arte\_fact](https://www.ruby-forum.com/u/arte_fact)\
**Post date:** [June 14, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/css-class-as-parameter/140476/1 "2008-06-14T19:13:50Z")

</div>

hello,

I would like to know how could it be possible to set a css class as  
parameter and a default one.

For instance class=“active” will be located on the first, second  
lines, depending on the action.

application.html.erb:

- Tasks
- Categories
- Calendar
- Eisenhower matrix

Any help would be highly appreciated.

bye

---

<div class="post-metadata">

**Author:** ![arte\_fact](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@arte\_fact](https://www.ruby-forum.com/u/arte_fact)\
**Post date:** [June 14, 2008, 7:25pm UTC](https://www.ruby-forum.com/t/css-class-as-parameter/140476/2 "2008-06-14T19:25:32Z")

</div>

> For instance class=“active” will be located on the first, second  
> lines, depending on the action.
> 
> application.html.erb:
> 
> -

things.each\_with\_index do |thing, index|

- \>Tasks

That’s just the sketch of the behaviors - but you must clean it up. The  
2  
and the ‘foo’ should appear in a table, preferably inside the thing  
model.  
Controllers should have the minimum possible logical statements, and  
View  
should have less.

- Tasks

---

<div class="post-metadata">

**Author:** ![arte\_fact](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@arte\_fact](https://www.ruby-forum.com/u/arte_fact)\
**Post date:** [June 14, 2008, 7:44pm UTC](https://www.ruby-forum.com/t/css-class-as-parameter/140476/3 "2008-06-14T19:44:26Z")

</div>

Thanks for helping.

Does it mean that I need to create a get\_class function in each model  
(tasks, categories, calendar …)?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![arte\_fact](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@arte\_fact](https://www.ruby-forum.com/u/arte_fact)\
**Post date:** [June 15, 2008, 4:47am UTC](https://www.ruby-forum.com/t/css-class-as-parameter/140476/4 "2008-06-15T04:47:09Z")

</div>

You could use a method call from a helper.

For your example:

in the application.html.erb

- Tasks
- Categories
- Calendar
- Eisenhower matrix

then in the application\_helper.rb

def get\_class(active\_action)  
“active” if @active\_action == active\_action  
end

then in your actions set the @active\_action variable

for your default, you could set the @active\_action in the  
application.rb controller, then it will be overwritten if some action  
specifically overrides the variable

---

<div class="post-metadata">

**Author:** ![arte\_fact](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@arte\_fact](https://www.ruby-forum.com/u/arte_fact)\
**Post date:** [June 15, 2008, 7:18am UTC](https://www.ruby-forum.com/t/css-class-as-parameter/140476/5 "2008-06-15T07:18:50Z")

</div>

If you are trying to highlight the active tab a good way of doing it is  
by giving all the tabs an id as well as a body id for each of the pages  
that the tabs exist on. Once you do this you have control of the active  
tab style.

ex.

- ...
- ...
...
# css

# the active tab

body#tasks li#task\_tab, body#categories li#category\_tab … {  
…  
}

# the inactive tabs

ul#tabs { … }
