My current setup looks like this:
In the uploads_controller.rb file:
class UploadsController < ApplicationController
before_action :set_upload, only: [:show, :edit, :update, :destroy]
# GET /uploads
def index
@uploads = Upload.all
update_file_status
@uploads = Upload.all
end
# Other controller actions here...
end
Then in the routes.rb file:
match 'uploads/refresh_table', to: 'uploads#refresh_table', via: :get
resources :uploads
Content of uploads.js.coffee file:
$(document).ready ->
setInterval refresh_table, 5000
refresh_table = ->
$.ajax url: "/uploads/refresh_table"
Inside views/uploads/index.html.erb:
<table class="table table-striped">
<thead>
<tr>
<!-- table headers here -->
</tr>
</thead>
<tbody>
<%= render (@uploads)%> <%# partial _upload.html.erb %>
</tbody>
</div>
</table>
Partial view _upload.html.erb:
<tr id= "uploads_table_rows">
<!-- content for each upload item -->
</tr>
Refresh table view in refresh_table.js.erb:
$('#uploads_table_rows').html("<%=escape_javascript(render(@uploads)) %>");
Issue arises when accessing some_url/uploads/refresh_table:
ActionController::UnknownFormat
Request parameters
{"controller"=>"uploads", "action"=>"refresh_table"}
Server output:
Started GET "/uploads/refresh_table" for 127.0.0.1 at 2014-01-02 21:10:26 -0500
Processing by UploadsController#refresh_table as HTML
Upload Load (0.3ms) SELECT `uploads`.* FROM `uploads`
Completed 500 in 2ms
ActionController::UnknownFormat - ActionController::UnknownFormat:
After troubleshooting for 2 days, I can confirm that the routing is correct, but the JavaScript view is not being triggered. Assistance would be greatly appreciated. Thank you.