当我使用换行符时,为什么我的text_area会添加缩进? - Ruby on Rails

时间:2022-04-09 20:44:52

I am getting a bug when I use a text_area in my rails app. The box takes line breaks, and makes them indentation. Here is a screen shot, any idea where these indentations are coming from?

我在rails应用程序中使用text_area时遇到错误。该框采用换行符,并使其缩进。这是一个屏幕截图,这些缩进来自哪里?

https://files.getdropbox.com/u/312568/Picture%2031.png

2 个解决方案

#1


I had this problem with some early versions of the haml plugin. If you are saying:

我有一些haml插件的早期版本存在这个问题。如果你说:

= f.text_area :body

you might try

你可能会试试

~ f.text_area :body

instead. This invokes whitespace preservation, which is nice for user-entered text.

代替。这会调用空白保留,这对于用户输入的文本很有用。

#2


Maybe try trimming your text using .strip

也许尝试使用.strip修剪文本

  str.strip => new_str

Returns a copy of str with leading and trailing whitespace removed.

   "    hello    ".strip   #=> "hello"
   "\tgoodbye\r\n".strip   #=> "goodbye"

If it doesn't work, I'll need more code to assist you

如果它不起作用,我将需要更多代码来帮助您

#1


I had this problem with some early versions of the haml plugin. If you are saying:

我有一些haml插件的早期版本存在这个问题。如果你说:

= f.text_area :body

you might try

你可能会试试

~ f.text_area :body

instead. This invokes whitespace preservation, which is nice for user-entered text.

代替。这会调用空白保留,这对于用户输入的文本很有用。

#2


Maybe try trimming your text using .strip

也许尝试使用.strip修剪文本

  str.strip => new_str

Returns a copy of str with leading and trailing whitespace removed.

   "    hello    ".strip   #=> "hello"
   "\tgoodbye\r\n".strip   #=> "goodbye"

If it doesn't work, I'll need more code to assist you

如果它不起作用,我将需要更多代码来帮助您