如何将HTML标记存储到DB中

时间:2013-09-02 06:45:02

标签: ruby-on-rails database tinymce

我在Tiny Mce Editor 4.0.5中使用Rails 2

new.html

<% form_for @custom, :url=>"create" do |c| -%>
  <%= c.text_area 'description' %>
  <%= c.submit %>
<% end %>

创建操作:

CustomReport.create(params[:custom_report][:description])

提交表格后我得到了

enter image description here

未定义的方法`stringify_keys!'

沿着那个我试过

CustomReport.create(:description => params[:custom_report][:description])

但它不存储任何HTML标签,那么我如何将标签存储到我的数据库中?

2 个答案:

答案 0 :(得分:0)

CustomReport.create(:description => params[:custom_report][:description])

应该为你完成这项工作,但Rails自然会逃脱html标签,阻止你做你需要调用的东西:

[html_safe](http://apidock.com/rails/String/html_safe)

raw

在您对带有html标签的字符串的视图中(这不是安全的做法,您应该确保字符串在考虑之前是真诚安全的,因为它可能会使您的应用暴露于攻击中)

答案 1 :(得分:0)

使用xss_terminate插件

在我的模型中CustomReport

  

xss_terminate:except =&gt; [:描述]

简单易行。