我如何在 Rails 4 中提供由 HTML 格式组成的 JSON 响应
{"result" : "<div><p>Some content #1</p><div><p>Some content #2</p><div><p>Some content #3</p>"}
这可以使用事件模型序列化器来完成吗?
我想用数据库中的数据预先格式化我的响应,然后将其附加到正文。
最佳答案
ActiveRecord::AttributeMethods::Serialization::ClassMethods
# Serialize preferences using JSON as coder.
class User < ActiveRecord::Base
serialize :preferences, JSON
end
关于ruby-on-rails - Rails 4 - JSON 响应中的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32011944/