From 3123b29b080bdd04121ca31e39c6c708166edfe3 Mon Sep 17 00:00:00 2001 From: Kazuki Kinebuchi Date: Tue, 20 Oct 2020 12:39:46 +0000 Subject: [PATCH] =?UTF-8?q?[Fix]#115/=E3=83=8F=E3=82=A4=E3=83=91=E3=83=BC?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=AF=E3=81=AE=E5=8F=97=E4=BF=A1=E5=81=B4?= =?UTF-8?q?=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=82=A8=E3=83=A9=E3=83=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/chat_messages_helper.rb | 8 +++++--- app/views/chat_messages/_chat_message_left.html.erb | 2 ++ app/views/chat_messages/_chat_message_right.html.erb | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/helpers/chat_messages_helper.rb b/app/helpers/chat_messages_helper.rb index 071b866..eab4b35 100644 --- a/app/helpers/chat_messages_helper.rb +++ b/app/helpers/chat_messages_helper.rb @@ -3,11 +3,13 @@ module ChatMessagesHelper require "uri" def content_url_to_link(content) + # 左右のパーシャルで呼び出すため、contentが二重に書き換えられるのを防ぐため、dupメソッドでコピーしてcontentを複数用意する + dup_content = content.dup # URI.extractで引数の[“http”, “https”].uniqで引数のcontentが「httpかhttps」のいずれかで始まるテキスト要素を重複を削除した形で配列を生成 - URI.extract(content, ["http", "https"]).uniq.each do |url| + URI.extract(dup_content, ["http", "https"]).uniq.each do |url| # 「gsub!」メソッドでcontentをの値を”< a href=”#{url}”target=”_blank”>#{url}”に置換 - content.gsub!(url, "#{url}") + dup_content.gsub!(url, "#{url}") end - content + dup_content end end diff --git a/app/views/chat_messages/_chat_message_left.html.erb b/app/views/chat_messages/_chat_message_left.html.erb index 491242a..836dff6 100644 --- a/app/views/chat_messages/_chat_message_left.html.erb +++ b/app/views/chat_messages/_chat_message_left.html.erb @@ -5,7 +5,9 @@ <% end %>
+ <%# binding.pry if content.match(/^http/) %> <%= content_url_to_link(content).html_safe %>
+ <%= created_at.strftime("%Y-%m-%d %H:%M")%>
\ No newline at end of file diff --git a/app/views/chat_messages/_chat_message_right.html.erb b/app/views/chat_messages/_chat_message_right.html.erb index 832d2c1..02a1d54 100644 --- a/app/views/chat_messages/_chat_message_right.html.erb +++ b/app/views/chat_messages/_chat_message_right.html.erb @@ -5,7 +5,6 @@ <% end %>
- <%# binding.pry if content.match(/^http/) %> <%= content_url_to_link(content).html_safe %>
<%= created_at.strftime("%Y-%m-%d %H:%M")%>