“neue Linie in Ruby” Code-Antworten

So erhalten Sie eine neue Linie zum Anzeigen in Rails

<%= 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

neue Linie in 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

Ähnliche Antworten wie “neue Linie in Ruby”

Fragen ähnlich wie “neue Linie in Ruby”

Weitere verwandte Antworten zu “neue Linie in Ruby” auf Ruby

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen