useranon useranon - 5 months ago 143
Ruby Question

Undefined method html_safe for Nokogiri Html Document

I am trying to use .html_safe in the below description where I receive the error as Undefined method for Nokogiri HTML document.


@blog = Blog.find(19)
@description = Nokogiri::HTML.parse(@blog.description)'').each do |desc|
desc['href']= File.join(ActionController::Base.asset_host, desc['href'])


<p><%= @description.html_safe %></p>

Kindly advise.

Answer Source

html_safe is a Rails method defined on String but not on Nokogiri::HTML.

I would try to translate the Nokogiri document into a HTML first:

<p><%= @description.to_html.html_safe %></p>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download