How to use each in rails to display values of an array

-1

I have a @keyword variable which holds the string "cat dog mouse bird"

I want to display the values of each word under a span element.

My algorithm looks like

<%= @keyword.split.each {|key| "<span>#{key}</span>".html_safe %>

but when viewing it, it displays an array of [cat dog mouse bird]

RandomGuest

Posted 2013-11-01T15:41:51.347

Reputation: 101

Question was closed 2013-11-01T15:47:14.987

This question appears to be off-topic because it is about programming – slhck – 2013-11-01T15:47:14.987

Should get a better answer here http://stackoverflow.com/

– sgtbeano – 2013-11-01T15:53:32.147

Answers

1

<%= @keyword.split.map {|key| "<span>#{key}</span>".html_safe }.join("\n") %>

ChrisInEdmonton

Posted 2013-11-01T15:41:51.347

Reputation: 8 110

Thanks man. By the way sorry, I thought this was stack overflow, work is taking a toll on my sanity. – RandomGuest – 2013-11-01T15:51:01.263