array separate array ruby on rails
-
25-06-2021 - |
Pergunta
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?
Solução
-if is_manager(team)
= is_manager(team).map(&:fullname).join(',')
Outras dicas
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(',')
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow