开发者

How to insert line endings in Sinatra

开发者 https://www.devze.com 2023-01-31 08:24 出处:网络
I was wondering how I could pe开发者_开发问答rform output in multiple lines in Sinatra. Eg. get \'/test\' do

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消