0

I am trying to reload a partial contained inside a Foundation tab every few seconds.

apps/views/xrf_cocs/show.html.erb - This is where I'm initially rendering the partial

  <div class="tabs-panel" id="panel6v" style="border-left: solid 1px #f2f2f2">
    <%= render 'lead_reports/index' %>
  </div>

apps/controllers/xrf_cocs_controller.rb - This is where I'm populating the rails objects for the partial

def show
    @positive_lead_reports = LeadReport.all.to_a
    @positive_lead_reports.delete_if{|cur| cur.xrf_coc_id != @xrf_coc.id}

    @negative_lead_reports = LeadReportNeg.all.to_a
    @negative_lead_reports.delete_if{|cur| cur.xrf_coc_id != @xrf_coc.id}
end

apps/views/lead_reports/_index.html.erb - This is the gist of the code inside the partial

<div id="lead_reports">
    <% @positive_lead_reports.each do |lead_report| %>
       <table>
          <thead>
          </thead>
          <tbody>
          </tbody>
       </table>
    <% end %>
       ... repeat above for negative reports
</div>

Basically I'm trying to add a jQuery function inside my apps/views/xrf_cocs/show.html.erb file that will call the render 'lead_reports/index' every 3 seconds.

Can anyone offer some help with this?

Cody Pritchard
  • 635
  • 1
  • 9
  • 28

1 Answers1

0

render is a Ruby on Rails method. Therefore, I highly doubt that you can call it directly. The best way to refresh a partial view is probably to use an ajax request.

Is it possible to refresh partial frequently using Ajax?

Community
  • 1
  • 1
Philipp Braun
  • 1,583
  • 2
  • 25
  • 41
  • AJAX only works if there is a form submit. This is not submitting anything, there for no ajax request is sent that I can respond too. – Cody Pritchard Nov 06 '16 at 23:01
  • AJAX has nothing to do with a form submit. It is simply a way to transfer data. You can simply trigger an ajax request using setInterval. Please check the link above. – Philipp Braun Nov 06 '16 at 23:03