Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当用户输入<h1>John文本字段并保存时,我希望将其另存为>h1<John。
<h1>John
>h1<John
为了使它成为可能,我如何在我的模型中编码?
这是用户模型的name列。
name
您只需要创建一个回调:
class YourModel before_save :sanitize_name private def sanitize_name self.name = CGI::escapeHTML(name) end end