1

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

blogs_controller.rb

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

show.html.erb

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

Kindly advise.

useranon
  • 29,318
  • 31
  • 98
  • 146

1 Answers1

2

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>
spickermann
  • 100,941
  • 9
  • 101
  • 131