Question

i have the following code which is meant to be looping over an array, with a comma after each object expect the last idea

-if is_manager(team)
   - is_manager(team).map(&:fullname).each.join(',') do |name|
   = "#{name}"

it appears that the code is trying to be executed, but for some reason the .join element is causing it to error like below

undefined method `join' for #<Enumerator: ["Tom Garcia", "Paul McGuane"]:each>

what do i need to do, to have this working?

Was it helpful?

Solution

-if is_manager(team)
   = is_manager(team).map(&:fullname).join(',')

OTHER TIPS

Get rid of the "each" piece; join is to be called on an array directly and should return a string.

Meaning the following should suffice:

is_manager(team).map(&:fullname).join(',')

Edit: Seems you're using HAML, so you need the '=' for output, try the following:

-if is_manager(team)
   = is_manager(team).map(&:fullname).join(',')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top