Unknown Format error with respond_to in Rails. Correctly trying to implementing polling-to-update
You can try a shortcut like respond_to :html, :js
and see if that clears it up. Otherwise try something more explicit:
def show @simulation = Simulation.find(params[:id]) respond_to do |format| format.js { render: "some view"} format.html { redirect_to simulation_url } endend
format.js
in the :show
action will by default render show.js.erb
when show is called with ajax. The html response will be a redirect.
This blog post may be helpful.
Perhaps issue is with whatever calls the show action in the first place,and it's missing the remote: true
option ?
If its a link then try with remote: true
option, something like :
<%= link_to 'Show', simulation_path(my_simulation), remote: true %>
same if its a button
<%= button_to 'Show', simulation_path(my_simulation), remote: true %>
This should cause Rails to call the controller with correct format and in logs you should see JS mentioned, e.g.
Processing by SimulationsController#show as JS
Also in the partial you are probably missing the dataType, try :
$.ajax({ type: "PUT", url: "/simulations/#{params}", dataType: "script"})