views:

105

answers:

2

I'm trying provide a textarea for the user to enter javascript. Each time the form is saved more whitespace is appended throughout the content. Any ideas how to ensure this doesn't happen?

Using Rails

A: 

If you're using a meta-HTML framework such as HAML, you need to ensure that there's no indentation happening to the content of your tag. While this is usually not a problem with ERB, you do need to be aware that whitespace inside the tag is submitted with the form.

Have a look at the source of your page to see what is rendered. It would be useful to append that to your question as a code snippet if possible.

tadman
This is the textarea I have:<textarea class="code" wrap="hard" id="js" name="js"><%= @book.js %></textarea>
Jake
What does that look like when rendered into the page as HTML? That's where the trouble is. Vish also has an interesting remark.
tadman
+1  A: 

Add a hyphen to the inside of your final %> tag, to prevent Rails from adding a newline and some whitespace. And make sure there's no whitespace in the HTML, of course :)

e.g.

<%= <blah> -%>

instead of

<%= <blah> %>
Vish