Hi everyone,
I’m currently trying to learn rails and I’m writing my first test
application. I’ve got a MySQL Database with the field “the_quote” (the
field type is “text”) and I’ve inserted some values via scaffold. The
text field contains breaks that are being displayed properly in MySQL
but when I use <%= table.the_quote %> in the view the breaks don’t
show up.
On 5 Aug 2008, at 20:16, Leerlaufprozess wrote:
Hi everyone,
I’m currently trying to learn rails and I’m writing my first test
application. I’ve got a MySQL Database with the field “the_quote” (the
field type is “text”) and I’ve inserted some values via scaffold. The
text field contains breaks that are being displayed properly in MySQL
but when I use <%= table.the_quote %> in the view the breaks don’t
show up.
This isn’t really a rails or a mysql issue. HTML dictates that all
white space is basically the same as a single space, so line returns
are ignored and multiple spaces between 2 words accomplish nothing.
You need to translate the line returns into markup. The simple_format
helper does this.
Fred
Leerlaufprozess wrote:
Hi everyone,
I’m currently trying to learn rails and I’m writing my first test
application. I’ve got a MySQL Database with the field “the_quote” (the
field type is “text”) and I’ve inserted some values via scaffold. The
text field contains breaks that are being displayed properly in MySQL
but when I use <%= table.the_quote %> in the view the breaks don’t
show up.
Hi,
Line breaks don’t show when rendered in HTML on a browser. If you add
at the end of each line, it will render a break when viewed in a
web browser, otherwise HTML ignores whitespace so if you have extra
spaces they will just show as one space. I hope that makes sense.
Wow, thanks! I’m using <%= simple_format(table.the_quote) %> and it
works perfectly!
On 5 Aug 2008, at 20:31, Leerlaufprozess wrote:
Wow, thanks! I’m using <%= simple_format(table.the_quote) %> and it
works perfectly!
Don’t forget to pass the text through h first (eg
simple_format(h(table.the_quote))) or users can inject bad things into
your page.
Fred