Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Refresh a page in Ruby on Rails

I am a newbie in Ruby On Rails, Can someone tell me how to refresh a page.

  1. Without any values submitted
  2. With previous values submitted
like image 405
markiv Avatar asked Jan 19 '10 19:01

markiv


1 Answers

ActionView::Helpers::PrototypeHelper#periodically_call_remote:

  1. Without any values submitted

    <%= periodically_call_remote(:url => {}) %>
    
  2. With previous values resubmitted:

    <%= periodically_call_remote(:url => params) %>
    

You can provide a :frequency option to specify how often to call it.

You may also want to set up the format.js block in the controller to render an RJS template that will only update things that could change.

Edit: This approach was deprecated with version Rails 3.0

This question (Rails 3 equivalent for periodically_call_remote) provides a method for accomplishing this in newer versions of Ruby on Rails.

like image 156
EmFi Avatar answered Oct 20 '22 16:10

EmFi