Help us understand the problem. What is going on with this article?

simple_format で textデータに改行を反映させる

text_areaでデータを入力してそのまま表示させると改行が反映されずに読みづらい文章になってしまいます。

<%= form_with model: @post, local: true do |f| %>
  <%= f.label :text %>
  <%= f.text_area :description, rows: 5, class: 'form-control', id: 'post_description' %>
<% end %>

みたいなformに

hello.
hello.
hello.

と入力して

<%= @post.description %>

みたいな感じで普通に表示させると

hello.hello.hello.

改行が反映されずにくっついています。

調べるとsimple_formatを使うのがいいようです。

<%= simple_format(@post.description) %>
hello.
hello.
hello.

になるはずです。長い文章の入力でも大丈夫そうです。

chiaaaakiiiii
公務員 ▶︎ ニート ▶︎ エンジニアへ!|2019.12~ 日々の学習記録を発信|2020.3~ バイト開始|独学|Ruby|Rails|元公務員|社会福祉士|IT × 福祉を考える|30代未経験からエンジニア転職を目指す|プログラミング初学者のみなさん一緒にがんばりましょう|よろしくお願いします ^ ^ Twitter : @chiaaaakiiiii
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした