开发者

rails action_controller Processing by Controller ( #show as */* )

I am sending an ajax request to one of my controller#action but my development log shows

Processing by FormsController#show as */*

while this should have been FormsController#show as JS as its an ajax request

Due to this the its re开发者_如何学运维ndering the format that it finds first in my responds to block in the controller

Eg:-

respond_to do |format|
  format.html{ }
  format.js { }
end

if I send ajax request to my controller it doesn't work as expected as my controller renders html response while it should process JS request.

But if the respond_to block is in this way

respond_to do |format|
  format.js { }
  format.html{ }
end

It work as expected.

I think

Processing by FormsController#show as */* 

is responding to which ever format it finds first in respond_to block.

But my concern is why my development log is showing

Processing by FormsController#show as */*

instead of

Processing by FormsController#show as JS

when I have sent an ajax request. Am I doing something wrong or missing a small but important piece?


Update your Rails.js file.

I'm assuming you're using jQuery-Rails. Some time ago, Rails AJAX requests didn't automatically set the requested content-type. That has since been addressed, so if you update you shouldn't have */* as the highest-prioritity content-type in your HTTP headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜