Rails - Whitespace added to content of textarea on save
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 开发者_StackOverflowideas how to ensure this doesn't happen?
Using Rails
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.
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> %>
I converted the ERB to HAML and it works since that. (erubis 2.7.0, haml 4.0.4)
精彩评论