Abram
Abram

Reputation: 41874

Using a line break in a text area 'value'

I am working on a simple private messaging application and, when replying to a message, I would like to display the original message a few spaces down in the text area. Here is what I am putting:

<%= f.input :content, :as=>:text, :label => "Reply", :input_html => { :value=> "<br /><br />Original Message: #{@message.content}".html_safe } %>

and.. here is what I'm seeing:

enter image description here

Upvotes: 3

Views: 2067

Answers (3)

Daniel Rikowski
Daniel Rikowski

Reputation: 72514

The problem is that the HTML standard does not allow textarea elements to have any nested elements, only plain text is allowed.

To work around this you have to use normal line breaks via \n. (See this existing SO question)

Upvotes: 2

Erez Rabih
Erez Rabih

Reputation: 15788

Try this one:

<%= f.input :content, :as=>:text, :label => "Reply", :input_html => { :value=> ("<br /><br />" +"Original Message: #{@message.content}".html_safe) } %>

Upvotes: 1

Tudor Constantin
Tudor Constantin

Reputation: 26861

try with \n instead of <br/>, and also, apply html_safe only to @message.content, not to the whole string:

<%= f.input :content, :as=>:text, :label => "Reply", :input_html => { :value=> "\n\nOriginal Message: " + @message.content.html_safe } %>

Upvotes: 2

Related Questions