I was wondering how I could pe开发者_开发问答rform output in multiple lines in Sinatra. Eg.
get '/test' do
array= ["one","two","three"]
"#{array.each { |elem| elem}}"
end
ideally would have output:
one
two
three
not onetwothree
I'm fairly new to Sinatra and Ruby (first day of study) so please apology me for basic question (can't find answer anywhere)
Plain text newlines
["one", "two", "three"].join("\n")
or for HTML line breaks:
["one", "two", "three"].join("<br>")
Reference: http://ruby-doc.org/core/classes/Array.html#M002182
Note: It's not a sinatra problem. Newlines are intepreted differently in HTML, plain newlines aren't interpreted as such by HTML, unless they are inside a <pre>
block; outside <pre>
<br>
is used for linebreaks.
精彩评论