Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:26:37+00:00 2026-06-04T20:26:37+00:00

I have different headers that I would like to loop through based on a

  • 0

I have different headers that I would like to loop through based on a timer which should be executed every time a page loads. Currently what I have works one time but then stops after it changes the header the first time. I am not very good with javascript and would appreciate it if someone could point me in the right direction.

Below is what I have in place currently.

In lib/Rotator.rb:

class Rotator
 def self.header_rotator(number)
   partials = ["header", "header2", "header3", "header4", "header5"]
   random_header = partials[number]
 return random_header
 end
end

Then in the header section of application.html.haml I have:

var start_rotate = setTimeout(rotate, 5000);
     function rotate() {
      remote_function(:url => {:action})
      $("#header").replaceWith('#{escape_javascript( render :partial => "shared/#{Rotator.header_rotator(rand(5))}")}')
      start_rotate = setTimeout(rotate, 5000);
     }

As I said this works fine but only rotates one time then stops.

Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:26:39+00:00Added an answer on June 4, 2026 at 8:26 pm

    This is less about js and more about understanding what is running where and when.

    If you look at the HTML that is being rendered things should become clearer. That call to escape_javascript, render happens precisely once: when that string gets interpolated during the rendering of the main page load. So the second (and third, fourth, fifth…) times rotate() runs it is replacing the header with exactly the same HTML.

    Assuming you are using jquery, the load method can do this:

    $('#header').load('/some/server/path')
    

    Don’t forget to render without the layout when you respond to this request.

    Lastly, are you sure you want to use Ajax at all? You could just load all the header variants up front and use JavaScript to show them in turn. (there are a number of jquery cycle or slideshiw plugins that do precisely this)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database stored in memory of different files headers. I would like
I have a few Python packages that I would like to tidy up and
I have a concept for a framework of controls that I would like to
We have a topdirectory containing code for lots of different projects. I would like
I have a class that I would like to reference in my header file,
I have four different lists. headers , descriptions , short_descriptions and misc . I
I have different php output in jQuery-based tabs. This output is formed from database
I have different urls that points to the same code www.url1.com www.url2.com I need
I have two functions that have different enough logic but pretty much the same
On a page I have different element which I bound yo different Ajax calls.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.