Rails — Add a line break into a text area

前端 未结 11 1018
南旧
南旧 2020-12-12 10:21

I got a rails app where I can input a few paragraphs of text into my model. The problem is I dont know how to input any line breaks.

I\'ve tried to add \" {ln}{/ln}

11条回答
  •  误落风尘
    2020-12-12 11:19

    the problem with simple_format is that it's also adding other tags like


    ...
    if you just want line breaks without other tags i suggest you build a partial (lets call it line_break):

    <% text.split("\n").each do |t| %>
      <%= t %>
    <% end %>

    then, just call it from your view:

    <%= render partial: 'line_break', locals: {text: some_text} %>
    

提交回复
热议问题