title: Getting Action controller unknown format error- for rails 4 + unobtrusive javascript and AJAX call
body: <p>Ive got the following setup:</p>
  
  <p>uploads_controller.rb:</p>
  
  <pre><code> class UploadsController &lt; ApplicationController
      before_action :set_upload, only: [:show, :edit, :update, :destroy] 
  
     # GET /uploads
     def index
       @uploads = Upload.all
   update_file_status
   @uploads = Upload.all
     end
  
    # GET /uploads/1
    def show
    end
  
    # GET /uploads/new
    def new
  puts "Running uploads/new"
     @upload = Upload.new()
    end
  
   # GET /uploads/1/edit
  def edit
  end
  
  # POST /uploads
  def create
  
  @upload = Upload.new(upload_params)
  if @upload.save
      @upload.update!(:status =&gt; "1")
      @upload.update!(:f_path =&gt; "#{@upload.sourcedata.path}")
      redirect_to uploads_url, notice: "Upload for #{@upload.task.name} was successfully created with file #{@upload.sourcedata_file_name}."
      else
         redirect_to tasks_url, alert: "*** ERROR *** Upload for #{@upload.task.name} did not go through successfully. #{@upload.errors.messages}"
      end
    end
  
    # PATCH/PUT /uploads/1
  def update
      puts "Update method in Uploads controller received params = #{params.inspect}"
      puts "params[:upload][:job] = #{params[:upload][:job].inspect}"
      if (params[:upload][:job] == "parse")
          puts "Passed params[:job]== \"parse\" "
  
          redirect_to uploads_url, notice: "Parsing data from #{@upload.sourcedata_file_name}....."
          @upload.delay.add_data_to_DB()
      else
          if @upload.update(upload_params)
              redirect_to uploads_url, notice: "#{@upload.sourcedata_file_name} was updated"
          else
              redirect_to uploads_url, notice: "ERRRO #{@upload.sourcedata_file_name} could NOT be updated"
          end
      end
  end
  
  
    # DELETE /uploads/1
    def destroy
       @upload.destroy
  redirect_to uploads_url, notice: 'Couldnt parse file #{@upload.sourcedata_file_name}'
    end
  
  # GET /uploads/refresh_table
  def refresh_table
      @uploads = Upload.all
      update_file_status
      @uploads = Upload.all
      respond_to do |format|
          format.js # template marked refresh_table.js.erb will be evoked
          #format.html {redirect_to uploads_url}          
      end
  end
  
  
    private
     # Use callbacks to share common setup or constraints between actions.
     def set_upload
       @upload = Upload.find(params[:upload][:id])
     end
  
     # Only allow a trusted parameter "white list" through.
     def upload_params
  params.require(:upload).permit(:sourcedata, :task_id, :status, :f_path, :job)
     end
  
  def update_file_status
  @uploads.each do |u|
      if(File.exist?(u.f_path))
          puts "File #{u.sourcedata_file_name} exists"
      else
          puts "File #{u.sourcedata_file_name} has been removed"
          u.update!(:status =&gt; "-1")
      end
  end
  end
  
     end
  </code></pre>
  
  <p>Then I have routes.rb containing these lines:</p>
  
  <pre><code> match 'uploads/refresh_table', to: 'uploads#refresh_table', via: :get 
   resources :uploads
  </code></pre>
  
  <p>uploads.js.coffee:</p>
  
  <pre><code> $(document).ready -&gt;
      # will call refresh_table every 1 second
      setInterval refresh_table, 5000
  
   refresh_table = -&gt;
      $.ajax url: "/uploads/refresh_table"
  </code></pre>
  
  <p>views/uploads/index.html.erb</p>
  
  <pre><code> &lt;table class="table table-striped"&gt;
     &lt;thead&gt;
       &lt;tr&gt;
  
    &lt;th&gt;File name&lt;/th&gt;
    &lt;th&gt;Upload Date, Time&lt;/th&gt;
    &lt;th&gt;File Type&lt;/th&gt;
    &lt;th&gt;Program Dates in file&lt;/th&gt;
    &lt;th&gt;Total Rows&lt;/th&gt;
    &lt;th&gt;Rows read&lt;/th&gt;
    &lt;th&gt;Completed&lt;/th&gt;
    &lt;th&gt;Status&lt;/th&gt;
    &lt;th&gt;Actions&lt;/th&gt;
       &lt;/tr&gt;
     &lt;/thead&gt;
     &lt;tbody&gt;
       &lt;%= render (@uploads)%&gt; &lt;%# partial _upload.html.erb %&gt; 
     &lt;/tbody&gt;
  
   &lt;/div&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p>partial views/uploads/_upload.html.erb</p>
  
  <pre><code>  &lt;tr id= "uploads_table_rows"&gt;
  
      &lt;td&gt; &lt;%= upload.sourcedata_file_name%&gt;&lt;/td&gt;
           &lt;% path_arr = upload.f_path.split("\/")%&gt;
      &lt;td&gt;&lt;%= path_arr[-3..-2].join(", ").gsub!("_", "\:")%&gt;&lt;/td&gt;
      &lt;td&gt; &lt;%= upload.sourcedata_content_type%&gt;&lt;/td&gt;
      &lt;td&gt; &lt;%= upload.date_ranges.pluck(:date_range).join(", ")%&gt;
      &lt;td&gt; &lt;%= upload.total_rows%&gt;&lt;/td&gt;
      &lt;td&gt; &lt;%= upload.rows_completed%&gt;&lt;/td&gt;
      &lt;td&gt; &lt;%= number_to_percentage(upload.percentage_complete, :precision =&gt; 0)%&gt;&lt;/td&gt;
      &lt;/td&gt;
      &lt;%if (upload.status == 0 ) %&gt;
          &lt;td&gt;Error &lt;/td&gt;
      &lt;%elsif (upload.status == 1 ) %&gt;
          &lt;td&gt;File saved on server&lt;/td&gt;
      &lt;%elsif (upload.status == 3 ) %&gt;
          &lt;td&gt;File is being parsed &lt;/td&gt;  
      &lt;%elsif (upload.status == 2 ) %&gt;
          &lt;td&gt;File data already in Database &lt;/td&gt; 
      &lt;%else%&gt;
          &lt;td&gt;File doesn't exist on Server&lt;/td&gt;   
      &lt;%end%&gt;
          &lt;td&gt;&lt;%= render 'button', :upload =&gt; upload%&gt;&lt;/td&gt;
    &lt;/tr&gt;
  </code></pre>
  
  <p>then I have views/uploads/refresh_table.js.erb</p>
  
  <pre><code> $('#uploads_table_rows').html("&lt;%=escape_javascript(render(@uploads)) %&gt;");
  </code></pre>
  
  <p>When I navigate to</p>
  
  <pre><code>  some_url/uploads/refresh_table
  </code></pre>
  
  <p>I get an error in the browser:</p>
  
  <pre><code>ActionController::UnknownFormat
   Request parameters 
   {"controller"=&gt;"uploads", "action"=&gt;"refresh_table"}
  </code></pre>
  
  <p>server output is:</p>
  
  <pre><code> 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:
  </code></pre>
  
  <p>Ive been trying to debug this and make this work for 2 days with various approaches but unsuccessfully. Finally I know that the routing here works but somehow now the javascript view is not being evoked.</p>
  
  <p>Can someone please assit. Thanks</p>