Reloading a partial application on rails

I want to reload a particle every 3 seconds in a "new" view in my rails application.

I have this in my new.html.erb

 <h1>Controller#new</h1> This is my static content <%= render partial: 'dynamic' %> More Static content 

How to get this partial reboot every 3 seconds? Should I use unobtrusive javascript for this? How can I achieve this through ujs?

+8
javascript ajax unobtrusive-javascript ruby-on-rails partial
source share
1 answer

Put partial in div

  <div class="dynamic"><%= render partial: 'dynamic' %></div> 

You can do it using jquery like this

  $(document).ready( function() { setInterval(function() { $('.dynamic').load('/controller_name/action_name'); }, 3000); }); 

Now update the partial controller action to load new content

  def action_name render :partial => "directory_name/dynamic" end 

This will work .........

+16
source share

All Articles