0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【MySQL】【メモ】カラム内の改行が「\r\n」と表示するのを改めたい

Last updated at Posted at 2022-07-04

環境

  • Mac(12.2.1)
    • MacBook Pro (13-inch, 2020)
    • 2 GHz クアッドコアIntel Core i5
    • 16 GB 3733 MHz LPDDR4X
  • ruby (3.0.0p0)
  • rails (7.0.1)
  • mysql2 (0.5.3)

解決したい内容

DBのカラム(text型)の値の中に\r\nがあり、改行して表示しようとしたが、そのまま「\r\n」と表示されて困った

解決

viewにて該当するカラムに対してsimple_format()を使用

app/views/contents/home.html.erb
<%@test_result.each do |i|%>
<li><%=simple_format(i.egogram_type)%></li>
<li><%=simple_format(i.character)%></li>
<li><%=simple_format(i.stregth)%></li>
<li><%=simple_format(i.weakness)%></li>
<li><%=simple_format(i.people_around_you)%></li>
<%end%>

参考にした記事

Ruby on Rails - 入力した改行をそのまま表示する方法

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?