Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@chiaaaakiiiii

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

More than 1 year has passed since last update.

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.

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

0
Help us understand the problem. What is going on with this article?
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
chiaaaakiiiii
受託システム会社でコード書いたり設計したりしてます。 Twitter : @chiaaaakiiiii

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?