I have a loop which outputs some information I grabbed from a website. To make the information display in an readable fashion, I added a <br> to the string. However when it runs, it displays <br>, escaping the html. I’ve used html_safe and raw but neither works. What’s wrong with the code? The code is called in the view home (don’t worry I’ll move it once the code works).
<%=
require 'rubygems'
require 'nokogiri'
require 'open-uri'
time = Time.new
month = I18n.t("date.abbr_month_names")[time.month]
day = time.day
"#{month} #{day}"
#United States
cities = [
"sfbay", "losangeles", "athensga", "phoenix", "santabarbara", "denver",
"panamacity", "miami", "austin", "bakersfield", "keys", "newyork"
]
cities.map do |city|
#Search Terms
search_terms = ["mechanic", "car", "tech"]
search_terms.map do |term|
escaped_term = CGI.escape(term)
url = "http://#{city}.craigslist.org/search/jjj?query=#{escaped_term}&catAbb=jjj&
srchType=A"
doc = Nokogiri::HTML(open(url))
doc.css(".row").map do |row|
date = row.css(".itemdate").text
a_tag = row.css("a")[0]
text = a_tag.text
link = a_tag[:href]
if date = "#{month} #{day}"
@strings << "#{date} #{text} #{link}"
end
end
end
end
%>
Hmm not sure at all but try the following:
Another way, not solving yours but displaying with br at each line: