Ruby on rails 如何将HTML标记存储到数据库中
我正在Ruby on rails 如何将HTML标记存储到数据库中,ruby-on-rails,database,tinymce,Ruby On Rails,Database,Tinymce,我正在rails2中使用Tiny-Mce Editor 4.0.5 new.html <% form_for @custom, :url=>"create" do |c| -%> <%= c.text_area 'description' %> <%= c.submit %> <% end %> 提交表格后,我得到 未定义的方法'stringify_keys!' 我一直在努力 CustomReport.create(:descri
rails2
中使用Tiny-Mce Editor 4.0.5
new.html
<% form_for @custom, :url=>"create" do |c| -%>
<%= c.text_area 'description' %>
<%= c.submit %>
<% end %>
提交表格后,我得到
未定义的方法'stringify_keys!'
我一直在努力
CustomReport.create(:description => params[:custom_report][:description])
但是它不存储任何HTML标记,所以如何将标记存储到数据库中
CustomReport.create(:description => params[:custom_report][:description])
应该为您完成这项工作,但Rails自然会避开html标记,为了阻止Rails这样做,您需要调用:
[html_safe](http://apidock.com/rails/String/html_safe)
或
在您对带有html标记的字符串的看法中(这不是安全的做法,在考虑这一点之前,您应该确保字符串是真正安全的,因为它会使您的应用程序受到攻击)使用插件
在我的模型中CustomReport
xss_terminate:except=>[:description]
简单易用。数据库中的字段“description”类型是什么?description类型是string。请将其设置为文本并使用
params[:custom_report][:description]。html_safe
谢谢,但它并没有解决相同的错误。您是否使用了mysql
?如果不是,那么这将是一个问题,否则它不是一个问题,无论它是html或任何东西作为mysql保存
[html_safe](http://apidock.com/rails/String/html_safe)