0

I have a method that joins the items within my array and when they are called to the view they are presented as a sentence would, all on one line.

def ingredient_names(ingredients)
if ingredients
  ingredient_array = ingredients.map {|ing| ing.ingredient_name}
  ingredient_array.join("\n")
end
end

how would i go about getting each item in the array to appear as a list? so for example

flour
eggs
water

is there a method for this or would i change the

("\n)

Thanks

Richlewis
  • 15,070
  • 37
  • 122
  • 283

1 Answers1

1

try this

def ingredient_names(ingredients)
  return ''  if !ingredients

  ingredients.map(&:ingredient_name)*'<br/>'
end

in the view call it like

<%= raw(ingredient_names(ingredients)) %>
adc
  • 771
  • 4
  • 12