- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试使用 ajax 从 Controller 呈现 js 文件。这个确切的代码以前总是有效,甚至在其他方法中也有效,但我突然开始收到这个错误:
ActionController::UnknownFormat in MoviesController#vote
ActionController::UnknownFormat
电影 Controller :
def vote
...
respond_to do |format| #The error points to this line.
format.js
end
end
投票.js.erb:
$('#votes').html("<%= escape_javascript(render 'votes') %>");
电影.html.erb:
<%= render 'votes' %>
_votes.html.erb
<%= link_to "vote", vote_path, method: :post, remote: true %>
路线.rb:
post 'movies/vote' => 'movies#vote', as: 'vote'
为什么我突然收到这个错误?为什么它在不同的上下文中有效,但在这个上下文中却无效?
使用 Rails 4.0.10
应用程序跟踪:
app/controllers/movies_controller.rb:394:in `vote'
完整跟踪:
actionpack (4.0.10) lib/action_controller/metal/mime_responds.rb:372:in `retrieve_collector_from_mimes'
actionpack (4.0.10) lib/action_controller/metal/mime_responds.rb:189:in `respond_to'
app/controllers/movies_controller.rb:394:in `vote'
actionpack (4.0.10) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.10) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.10) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.10) lib/active_support/callbacks.rb:413:in `_run__1492335060096380544__process_action__callbacks'
activesupport (4.0.10) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.10) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.10) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.10) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.10) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.10) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.10) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.10) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.10) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.10) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.10) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.10) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.10) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.0.10) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.10) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.10) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.10) lib/action_dispatch/routing/route_set.rb:676:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.10) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.10) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.10) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.10) lib/active_support/callbacks.rb:373:in `_run__2656547782179467807__call__callbacks'
activesupport (4.0.10) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.10) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.10) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.10) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.10) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.10) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.10) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.10) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.10) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
actionpack (4.0.10) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
railties (4.0.10) lib/rails/engine.rb:511:in `call'
railties (4.0.10) lib/rails/application.rb:97:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
rack (1.5.5) lib/rack/handler/webrick.rb:60:in `service'
/home/greg/.rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/greg/.rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/greg/.rvm/rubies/ruby-2.0.0-p648/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
最佳答案
您可以为路由助手指定 format
选项,以指示链接为 js
而不是默认的 html
。像这样指定它:
<%= link_to "vote", vote_path(format: :js), method: :post, remote: true %>
过去,我在使用某些版本的 Rails 时遇到过问题,但我只有关于这方面的轶事证据。我发现在那种情况下确实有效的是:
<%= link_to "vote", "#{vote_path}.js", method: :post, remote: true %>
在第二种情况下,您只需将 .js
扩展名附加到将触发 js
格式的 url 路径。不优雅和蛮力,只能在尝试正确方法失败后使用,但它确实有效。
关于javascript - "respond_to do |format|"抛出 UnknownFormat 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37041729/
来自 java docs 公共(public) FileWriter(String fileName) 抛出 IOException 抛出: IOException - 如果指定的文件存在但它是目录而
我使用以下代码将我的 .net 客户端(基于 CQL)连接到 3 节点 Cassandra 集群。我以 30 条记录/秒的速度(从 RabbitMQ)获取数据,并且它们顺利地存储在 cassandra
如果在读取文件时缺少字段,我应该捕获 NoSuchElementException。如果缺少一个字段,我只需要跳到文件的下一行。我的问题是,我在哪里实现我的 try/catch 代码来做到这一点?这是
我正在尝试使用 ASP.NET MVC 实现 OpeinID 登录。我正在尝试按照 http://blog.nerdbank.net/2008/04/add-openid-login-support-
学习使用 Java 进行 xml 解析,并且正在编写一个测试程序来尝试各种东西。所有测试 System.out.println() 都是我在控制台中所期望的,除了 childElement 返回 [n
我正在尝试使用 SwingUtilities 创建 JFrame Thread tt = new Thread(new Runnable() { public void run
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我写了这段代码: MethodInfo method2 = typeof(IntPtr).GetMethod( "op_Explicit", Bind
我开始学习 Java,并且正在根据书本做一些练习。在执行此操作时,我遇到了以下错误:线程“main”java.util.InputMismatchException 中出现异常。我正在编写一个简单的程
我有一个文本文件,其中前两行是整数 m 和 n,然后有 m 行,每行都有 n 管道分隔值。我编写了一个程序,读取文件并使用文件中的值创建 m*n 数组,它工作了无数次,然后突然,使用相同的代码,使用相
所以我尝试使用在另一个类中生成的 bean 以在主应用程序中使用 package com.simon.spring.basics.properties; import org.spri
我还没有完成这个应用程序,但我希望在我的手机上看到它的样子。但是,它会强制关闭并引发 InstantiationException。 logcat 异常: 09-19 20:13:47.987: D/
我想从 UIViewController 加载一个基于 SwiftUI 的 View ,该 View 读取包本地的 json。仅 swiftUI 项目中的代码和绑定(bind)工作正常,当我利用 UI
'java.net.SocketTimeoutException:连接超时' 循环一段时间后我收到此错误。为什么我会收到 SocketTimeoutException?我该如何修复这个错误? @Ove
当有 null 值时抛出 ArgumentNullException() 是个好主意吗? This thread 没有提到在 null 上抛出的最明显的异常。 谢谢 最佳答案 ArgumentNull
我得到这个异常: NullReferenceException Object reference not set to an instance of an object at Namespace
所以其中一个方法的描述如下: public BasicLinkedList addToFront(T data) This operation is invalid for a sorted list
我正在使用 Intellij Idea,当我去生成 JavaDocs(通过工具 -> 生成 JavaDoc)时,我抛出了一个 IllegealArgumentException,没有关于发生了什么问题
我正在学习 C++ 中的互斥锁,但以下代码(摘自 N. Josuttis 的“C++ 标准库”)有问题。 我不明白为什么它会阻塞/抛出除非我在主线程中添加this_thread::sleep_for(
我正在试验 JavaFX 标签和组,通过鼠标拖动将它们移动到屏幕上。新节点从一些线程添加到动画组。但是,有时我会突然看到以下异常 - 我假设,当某些节点重叠时。但是不知道是什么问题……因为不涉及我的代
我是一名优秀的程序员,十分优秀!