出于某种原因,
带有caches_action的render json: User.all
:index返回内容类型text / html。如何强制它到application / json?
在:
def index
render json: User.all.to_json
end
使用Content-Type返回json:' application / json'
后:
caches_action :index
def index
render json: User.all.to_json
end
使用Content-Type返回json:' text / html'。从技术上讲,它是html中的json字符串。
答案 0 :(得分:1)
最安全的方法是根据文档将你的路线声明为config/routes.rb