1

I have a helper function in which class is shown when a specific controller is open.

Helper:

     def cssclass
     'class="tab_gen_active3"' if controller_name == "user_brands"

     end

I am having difficulty to apply 'else' in which "tab_gen3" css class is activated when controller_name = "user_categories". Any idea how to do this.

2 Answers 2

1

If you want more elegant solution - add conditional class to helper method:

def cond_class(condition, true_class, false_class = '')
  condition ? true_class : false_class
end

and use it in view like this - im my case it haml:

.example-div{:class => cond_class(controller_name == 'user_brands', 'tab_gen_active3')}
Sign up to request clarification or add additional context in comments.

Comments

0

Change it to

controller_name == "user_brands" ? 'class="tab_gen_active3"' : ''

1 Comment

Great. Works like charm. I don't know how i missed it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.