简体   繁体   中英

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. But once i click the link, it gives me an error message 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

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

#poc waiting...

_load_poc.js.erb

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

index_controller.rb

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

routes.rb

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

Processing by IndexController#load_poc as HTML is the problem. Your action is only responding to requests as JS, but it's sending through as an HTML request. Your request should look like: Processing by IndexController#load_poc as JS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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