I want escape html for data in controller, I found 2 ways:
text.gsub('<', '<').gsub('>', '>')
OR
CGI.escapeHTML(text)
What is the best, why?
I want escape html for data in controller, I found 2 ways:
text.gsub('<', '<').gsub('>', '>')
OR
CGI.escapeHTML(text)
What is the best, why?
The best way is probably to just assign the data to instance variables and then output them in the view, which will handle encoding automatically:
controller:
something.html.erb
Will output:
The view will do the right thing in most cases.