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 9122553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:07:51+00:00 2026-06-17T06:07:51+00:00

I have a banner in a sidebar that is displayed by a chunk of

  • 0

I have a banner in a sidebar that is displayed by a chunk of HTML, in my Ruby on Rails application in my views/home/index.html But I have another banner. I want to randomly display one of these, every time someone views the page.

<section id="audio-banner">
<a onclick="changeClass("#swap") href="#">
<img src="someImage.gif" >
</a>
</section>

and

<section id="audio-banner">
<a onclick="changeClass("#swap2") href="#">
<img src="someOtherImage.gif" >
</a>
</section>

I am new to Ruby and Rails. I’m not sure where to put the predefined HTML (model, controller, helper, etc.) or how to write the function that will display one of these two randomly.

I started out by editing helpers/home_helper.rb and inserted the following code

module StoreHelper
  def randomAudio
    audio1 = '<section id="audio-banner">'
    audio1 << '<a onclick="changeClass("#swap"); return false;" href="#">'
    audio1 << '<img src="some.gif">'
    audio1 << '</a>'
    audio1 << '</section>'
    audio1
    audio2 = '<section id="audio-banner">'
    audio2 << '<a onclick="changeClass("#swap2"); return false;" href="#">'
    audio2 << '<img src="someOther.gif" alt="Estate">'
    audio2 << '</a>'
    audio2 << '</section>'
    audio2
  end
end

But that’s as far as I got, because I know it isn’t correct. Any help would be great. Thanks.

  • 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-17T06:07:53+00:00Added an answer on June 17, 2026 at 6:07 am

    Here’s an improved version of your code (should work). Note that in real app, you should move these HTML parts to partials. But here, for the sake of simplicity, let’s leave them inline.

    module StoreHelper
      def randomAudio
        audio1 = <<-HTML
        <section id="audio-banner">
          <a onclick="changeClass("#swap"); return false;" href="#">
            <img src="some.gif">
          </a>
        '</section>
        HTML
    
        audio2 = <<-HTML
        <section id="audio-banner">
          <a onclick="changeClass("#swap2"); return false;" href="#">
            <img src="someOther.gif" alt="Estate">
          </a>
        </section>
       HTML
    
       # pick one of them randomly
       [audio1, audio2].sample
      end
    end
    

    It uses heredocs to define HTML snippets without extra noise. Also read about Array#sample.

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

Sidebar

Related Questions

I have a Javascript greeting that greets new users with a drop down banner
I have the following index.html page set-up: <html> <head> </head> <body> <div id=container> <div
I have a ad banner that has a form and this is used by
I have some banner ads in AS3 that I need to make work with
I have a flash banner that I want to replace with a static image
In my layout page, I have a banner that I only want to show
I'm creating a Sencha Touch application. I would like to have a banner docked
I have a banner (XML_Banner.swf) that is supposed to load and rotate images from
I'm using a combination of Jquery and html imagemap to have a banner with
I'm noticing a strange behaviour in Firefox. I have a banner that's positioned absolutely

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.