简体   繁体   English

在Rails中使用link_to渲染部分onclick时,返回错误ActionController :: UnknownFormat

[英]Error ActionController::UnknownFormat returned when rendering partial onclick with link_to in rails

I am trying to render a new view to my div onclick with link_to. 我正在尝试使用link_to向div onclick渲染新视图。 But once i click the link, it gives me an error message ActionController::UnknownFormat. 但是,一旦我单击链接,它就会给我一条错误消息ActionController :: UnknownFormat。

The following is the error log, 以下是错误日志,

Started GET "/load_poc" for 127.0.0.1 at 2014-11-13 20:29:58 +0000
Processing by IndexController#load_poc as HTML
Completed 406 Not Acceptable in 0ms

ActionController::UnknownFormat (ActionController::UnknownFormat):
  app/controllers/index_controller.rb:7:in `load_poc'

Can you please tell me how to fix this problem? 您能告诉我如何解决此问题吗? Is this a routing issue or am I missing some important steps? 这是路由问题还是我错过了一些重要步骤? Thank you very much! 非常感谢你!

Following is my code: 以下是我的代码:

index.html.haml index.html.haml

= link_to "#{@xx}", load_poc_path(@xx), :remote => true, :method => :get

#poc waiting...

_load_poc.js.erb _load_poc.js.erb

$('#poc').html("<%= escape_javascript(render :partial => 'poc') %>");

index_controller.rb index_controller.rb

def load_poc
    respond_to do |format|
        format.js
    end
end

routes.rb routes.rb

match 'load_poc', :to => IndexController.action("load_poc"), via: 'get'

Processing by IndexController#load_poc as HTML is the problem. 问题是Processing by IndexController#load_poc as HTML Your action is only responding to requests as JS, but it's sending through as an HTML request. 您的操作仅以JS响应请求,但以HTML请求的形式发送。 Your request should look like: Processing by IndexController#load_poc as JS 您的请求应类似于: Processing by IndexController#load_poc as JS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM