I just referred to this article lol https://qiita.com/kamotetu/items/1aa94994985c720668e4
with form_for and form_with Line breaks when entering text → I can't do it at all! It became. I want to display it as it is.
input form
new.html.erb
<div class="from-group mb-4">
<%= f.label :introduction, "Introduction", class: "form-label" %><br />
<%=f.text_area :introduction, class: "form-control", id:"user-introduction", size: "90x5", maxlength: "1000", placeholder: "Write an introductory text"%>
</div>
Enter a post display
show.html.erb
<%[email protected]%>
Then I can't break a line. I want to solve this.
show.html.erb
<%=safe_join(@user.introduction.split("\n"),tag(:br))%>
Just change it to I did well!
This description is
It becomes possible.
When the input home was not validated, an error occurred if it was sent blank. In such a case
show.html.erb
<%if @user.introduction.nil? %> #If the introductory text remains "empty", an error will occur, so nil?=Add when true
<%[email protected]%> #No validation
<% else %>
<%=safe_join(@user.introduction.split("\n"),tag(:br))%> #If the introductory text is not "empty", it will be reflected normally
<%end %>
I solved it with.
Recommended Posts