应用/抢答/项目/ show.html.erb
<h1><%= @item.name %></h1>
<ul>
<li><%= @item.price %> руб.</li>
<li><%= urls_to_images(@item.description) %></li>
<li>Вес: <%= @item.weight %> кг.</li>
</ul>
应用/助手/ application_helper.rb
module ApplicationHelper
def urls_to_images(s)
s.gsub! /\s(http:\/\/.*?)/ , '<img src="\1"/>'
s.html_safe
end
# def urls_to_links(s)
#
# end
end
浏览器界面:
显示的文字。为什么不输出链接?
答案 0 :(得分:0)
我认为你在urls_to_images
方法中犯了错误。试试这个 -
def urls_to_images(s)
s = s.gsub! /\s(http:\/\/.*?)/ , '<img src="\1"/>'
s.html_safe
end
答案 1 :(得分:0)
def urls_to_images(s)
s.gsub! /\s(http:\/\/.*?)(\s|\Z)/ , '<img src="\1"/>'
s.html_safe
end
**现在有效**