Ruby ActionController::UnknownFormat 异常怎么处理

qin287624952 · 2015年02月05日 · 最后由 qin287624952 回复于 2015年02月05日 · 3669 次阅读

我想写一个修改附件的方法,当调用此方法时指向一个 js 文件,然后让 js 文件执行代码弹出一个修改附件的窗口。但执行时在 controller 里面总是报 UnknownFormat 异常,没能正确调用指定的 js 文件。想问问这个问题怎么解决呢? 以下是代码: Controller 中 def edit_attachment respond_to do |format| format.js end end Routes 中 resources :dynamic_topics do member do get 'edit_attachment' patch 'update_attachment' end end View 中 = link_to '附件管理', edit_attachment_dynamic_topic_path(dynamic_topic), class: 'btn btn-primary btn-xs'

控制台报错:Processing by DynamicTopicsController#edit_attachment as HTML 浏览器报错:ActionController::UnknownFormat

求排版……而且,views 中的 link_to 指向的是 html 格式,你应该加上remote: true

controller 中只指定了响应 format 为 js 的时候,默认是请求 html,找不到匹配 format。

#1 楼 @cassiuschen 恩,忘了加 remote: true 了。已解决,谢谢。

qin287624952 关闭了讨论。 09月28日 10:32
需要 登录 后方可回复, 如果你还没有账号请 注册新账号