“Nova linha em Ruby” Respostas de código

Como colocar a nova linha para exibir em trilhos

<%= obj.description %>
Even though your value may be "One  \t  \n  \n  Two", it will show up on the screen as "One Two".

To get those new line characters to actually separate the lines when displayed, you'll need to convert them to HTML before rendering:

<%= obj.description.gsub(/\n/, '<br/>') %>
Of course, if users are entering data that will be included in your HTML, you should be escaping the values to protect against XSS. If new lines are the only thing you need to support, it should be as simple as this:

<%= h(obj.description).gsub(/\n/, '<br/>') %>
Jake_bdr

Nova linha em Ruby

str = "hello world"
str_with_new_line = "hello world/n"

# You also can output values differently
# 1. print
# Outputs the value with no new line
# 2. puts 
# Outputs the value with new line

str1 = "hello"
str2 = "world"

puts str1
puts str2

# Output: hello
#         world


print str1
print str2

# Output: helloworld
schwarz_koder

Respostas semelhantes a “Nova linha em Ruby”

Perguntas semelhantes a “Nova linha em Ruby”

Mais respostas relacionadas para “Nova linha em Ruby” em Ruby

Procure respostas de código populares por idioma

Procurar outros idiomas de código