如何将HTML标记存储到DB中
我在Rails 2
使用Tiny Mce Editor 4.0.5
。
new.html
"create" do |c| -%>
创建动作:
CustomReport.create(params[:custom_report][:description])
提交表格后我得到了
undefined方法`stringify_keys!’
沿着那个我试过
CustomReport.create(:description => params[:custom_report][:description])
但是它不存储任何HTML标签,那么我如何将标签存储到我的数据库中呢?
使用xss_terminate插件
在我的模型CustomReport
xss_terminate:except => [:description]
简单易行。
CustomReport.create(:description => params[:custom_report][:description])
应该为你做的工作,但Rails自然会逃脱html标签,阻止铁路做你需要调用:
[html_safe](http://apidock.com/rails/String/html_safe)
要么
生的
在你的视图中使用html标签的字符串(这不是安全的做法,你应该确保字符串在考虑之前是真诚安全的,因为它可以使你的应用程序暴露于攻击)