0

In my model I have a field type string called god_type.

Example:

Ice,Fire

Ranged,Cannon

Fire,Ranged

I'm going to be using Isotope to filter these models based on their god_type.

I need the output HTML to look like:

<div class="item Fire Ranged">
</div>

Here's what I've tried:

#gods-list.isotope-container
  - for god in @gods
    .item class='#{god.god_type.split(",").each { |c| c }}'
      a href='#{god_path(god)}' class='god'
        img src='#{god.thumbnail.url(:thumb)}'
        h2= god.name

And the resulting HTML:

<div class="item ["Fire", "Ranged"]">
    ...
</div>

What am I doing wrong?

Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
sergserg
  • 21,716
  • 41
  • 129
  • 182

1 Answers1

1

I'd suggest:

.item class='#{god.god_type.gsub(/\,/, " ")}'

You could also wrap it in a method, within a decorator, or directly in the model, or even an application helper. Here's a general idea:

class God
  def god_type_classes
    god_type.gsub(/\,/, " ").downcase
  end
end

# your view

.item class='#{god.god_type_classes}'

Noticed I've used .downcase on the string. This is just to address standard CSS naming (should be item fire ranged).

Damien Roche
  • 13,189
  • 18
  • 68
  • 96