7

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
Eimantas
  • 48,927
  • 17
  • 132
  • 168
markiv
  • 2,331
  • 2
  • 15
  • 8
  • 1
    When you say "refresh" do you mean the page will automatically refresh itself every "n" minutes, or is there a control (e.g., button) that the user will activate to refresh the page? – BryanH Jan 19 '10 at 19:58
  • it will automatically refresh – markiv Jan 19 '10 at 19:59

2 Answers2

7

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.

Community
  • 1
  • 1
EmFi
  • 23,435
  • 3
  • 57
  • 68
  • Your link seems to be broken. – Bach Aug 06 '15 at 11:26
  • 1
    Not broken, just deprecated. I've updated the link to point to the documentation of the last version of rails this was supported, I've also added a link to answer that provides an method of accomplishing this in newer versions of Rails. – EmFi Aug 06 '15 at 17:02
1

You could also use the below script to auto refresh a full page...

setTimeout("location.reload();",10000);
abcreddy
  • 102
  • 3
  • 19