I apologize for the long answer. I tried to reproduce your problem in several ways, but I think you can look in the wrong direction. I have included the whole story so that you can see if it all fits, and if she does not expect her, she will lead to an understanding that will help you solve the problem.
ActionController::UnknownFormat
happens before rendering view
If Rails presents you with an ActionController::UnknownFormat
, it means that your controller is not responding to the requested format. The error is raised by the respond_to
method, in the exact line that you selected.
If an error was made during rendering, then it would be bubbled through the line using format.html
or format.js
. Thus, this error, of course, is not caused by part of the rendering of the view.
Error ActionController::UnknownFormat
The only way to get the exact error message you sent is if I request the AJAX response page directly in the browser. Then you will see the Rails error page, which will also show you in what format the request was executed. You are probably requesting a page with a format other than html
or js
, in which case the ActionController::UnknownFormat
error is ActionController::UnknownFormat
, since your controller only responds to the html
or js
format.
I think the real problem is hiding somewhere else.
Playback from views/things/show.html.erb
I tried to reproduce the error in the views/things/show.html.erb
page. When you do this with your source code, I get a syntax error in the following line:
<%= link_to image_tag("UpArrowGray.jpg", class: "rand_up_vote"), remote: true, %>
This is due to the comma after remote: true
. Because of this, I suppose you did not constantly test the remote link. When testing without remote: true
, the reload_script
function launches a jQuery AJAX request. You do this with the following line:
$.get( "<%= upvoterandom_thing_path(:id => @rand.id) %>", function( data ) { });
This actually triggers an XHR request in */*
format. It basically tells Rails what any format will do. Here's what happens:
ThingsController
responds with the first format you defined in the respond_to
, which is the HTML format. This causes a redirect to your root path.- jQuery follows the redirect, again using the
*/*
format. - The controller in the root path responds with the first defined format or the default HTML if there is no
respond_to
. - JQuery then loads this answer.
It is not possible that an ActionController::UnknownFormat
could be raised from a ThingsController
when it is played as follows.
What I think
This is mostly a guessing job, so please correct me if I am wrong:
- You clicked the link of the deleted link and nothing happened.
- You added JavaScript to explicitly get the page through AJAX, but still nothing happened.
- You have visited
things/1/upvoterandom.js
(or similar) page directly in your browser. In this case, ActionController::InvalidCrossOriginRequest
would be raised. - You visited
things/1/upvoterandom.json
(I used JSON, but it could be any format other than HTML or JS), directly with your browser, and you got an ActionController::UnknownFormat
.
If so, you need to go back to step 1 and start reproducing the problem in the other direction:
- Go to the
things/1
page (or another page). - Open the developer tool / web inspector of your browser.
- Go to the view that shows the network connection (in Chrome, this is the "Network" tab).
- Now click on the link and see what happens between your browser and your Rails application. If a lot happens, you can often filter only for XHR, which only shows AJAX requests.
- If you see status there 500, you need to check the output of the Rails server for an error using stacktrace.
I can only guess what the actual cause of the problem is, but I think there might actually be some error in rendering the view. As you said, the only case when it does not work is partial. I hope this information helps you solve the problem.