When copying text on a Rails application page, it is displayed with spaces instead of paragraphs, and if you enter text from the keyboard, then Enter works like saving text. How to make the application displayed paragraphs?

The form:

<%= form_with(model: act, local: true) do |form| %> <% if act.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(act.errors.count, "error") %> prohibited this act from being saved:</h2> <ul> <% act.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="form-group"> <%= form.label :description %> <%= form.text_area :description, id: :act_description, class: "form-control" %> </div> <div class="actions"> <%= form.submit "Create", class: "btn btn-primary" %> </div> <% end %> 

view:

 <h1>Acts:</h1> <%= link_to 'New Act', new_act_path, class: "btn btn-primary btn-sm" %> <br><br> <% @acts.each do |act| %> <% if act.user == current_user %> <div class="alert alert-info"> <article class="lead"> <%= act.description %> <span class="float-right"> <%= link_to 'Edit', edit_act_path(act), class: "btn btn- primary btn-sm" %> <%= link_to 'Destroy', act, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-danger btn-sm" %> </span> </article> </div> <% end %> <% end %> <%= link_to 'New Act', new_act_path, class: "btn btn-primary btn-sm" %> 
  • It seems we are a little short of the code for your application page. Well, at least the form where you enter text. In general, it seems you need a WYSIWYG editor of some kind - Vasilisa
  • I tried the WYSIWYG editor, but it didn’t help. Or I did something wrong ... in the form I replaced form.text_field with form.text_area and the enterter in the form already switches to the next line, but after saving in the view, again all the text sticks together in one long line - Volodymyr Lopatsky

1 answer 1

Now I understand. You need to convert line breaks into something that HTML understands. In the rails for this is simple_format . That is, in the view should be:

 <article class="lead"> <%= simple_format(act.description) %> 
  • Indeed the problem was this. Thanks for the tip. Now everything works as it should))) - Volodymyr Lopatsky
  • @ Volodymyr Lopatsky, always happy to help :) Next time, immediately add the code to the question, it’s so much easier to answer - Vasilisa