1

I'm writing a module to add functionality to the FlagShihTzu gem.

Basically it goes through the flags and outputs the keys for the ones assigned to the object. It's working, but I also want to be able to use a block in the view to do things with the output.

The problem is that it's outputting both the array from the module and the output from the block in the view.

module AwesomeFlags

  def my_flags(column = nil)
    a = self.flag_mapping
    if column.nil?
      c = a.values.map {|var| var.keys}.flatten
    else
      b = a[column]
      c = Array.[](b.keys).flatten
    end
    c.map {|var| self.send(var) ? "#{var.to_s} " : nil}.compact!
  end

end

In the view:

= book_offer.my_flags.each do |flag|
  = flag.titleize

What I get is:

Regular Complimentary regular complimentary
Gabe K
  • 133
  • 1
  • 7

1 Answers1

0

You should switch that to be:

- book_offer.my_flags.each do |flag|
  = flag.titleize

The = means to include the output of the method call, where - means to simply execute it. The each loop is returning the items in the list.

tadman
  • 194,930
  • 21
  • 217
  • 240
  • Perfect, thank you. Sometimes I get so into the deep stuff that the simple stuff eludes me. – Gabe K Sep 21 '11 at 19:04