Render dynamically vertical tabs and set classes depends on if statement I would like to refactor code below and get rid of if statements for classes from view.

.container
  .tabbable.tabs-left
    %ul.nav.nav-tabs
      - @related_tasks.each do |task|
        %li{class: ("active" if @task == task)}
          = link_to task.name, "#tab#{task.id}", data: { toggle: 'tab' }, class: @current_user_tasks.include?(task.id) ? '' : 'inactive' 

    .tab-content
      - @related_tasks.each do |task|
        .tab-pane{id: "tab#{task.id}", class: ("active" if @task == task)}
          = render 'task_tab', task: task
Helper methods are good for this.  In your view's helper file:

def task_link_class(task)
  if @current_user_tasks.include?(task)
    ''
  else
    'inactive'
  end
end


Some would prefer the trinary operator instead:

def task_link_class(task)
  @current_user_tasks.include?(task) ? '' : 'inactive'
end


And in your view:

= link_to task.name, "#tab#{task.id}", data: { toggle: 'tab' }, class: task_link_class(task)