response_with 返回未知格式 - rails [英] respond_with returns unknown format - rails
本文介绍了response_with 返回未知格式 - rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用通过 AngularJS
发送一些 json,在我有
I am using through AngularJS
to send some json, in the controller I have
respond_to :json
def create
respond_with Task.create(description: params[:description])
end
tasks
存储在数据库中,但随后我在日志中收到此消息
the tasks
is stored on the database, but then I get this message in my log
ActionController::UnknownFormat - ActionController::UnknownFormat:
(gem) actionpack-4.0.0/lib/action_controller/metal/mime_responds.rb:372:in `retrieve_collector_from_mimes'
(gem) actionpack-4.0.0/lib/action_controller/metal/mime_responds.rb:327:in `respond_with'
...
我尝试在我的路线中添加 resources :tasks, :defaults =>{:格式=>js"}
.我该如何处理这个问题?
I tried to add in my route resources :tasks, :defaults => {:format => "js"}
. How can I handle this problem ?
推荐答案
您希望默认格式为json",而不是js".
You want your default format to be "json", not "js".
Rails 有一个它期望的格式列表(基于默认值加上你或 gems 可以添加额外的已知响应类型.)Js 不是默认值之一
Rails has a list of formats that it is expecting (based on defaults plus you or gems can add additional known response types.) Js is not one of the defaults
这篇关于response_with 返回未知格式 - rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文