Reputation: 2753
When a user inputs <h1>John
to the text field and saves, I want it to be saved as >h1<John
instead.
To make it possible, how can I code in my model?
It's User model's name
column.
Upvotes: 1
Views: 27
Reputation: 4400
You just need to create a callback:
class YourModel
before_save :sanitize_name
private
def sanitize_name
self.name = CGI::escapeHTML(name)
end
end
Upvotes: 2