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

The Archive Base Latest Questions

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

I am trying to grasp interpolation and am trying to use a dynamic string

  • 0

I am trying to grasp interpolation and am trying to use a dynamic string ( i say dynamic as it can change all the time, I am pulling dates via a screen scrape for movie releases) and as an ID so that i can use bootstrap scrollspy in my project

I created a js fiddle using conventional ID’s and anchor tags that demonstrates what I am trying to achieve.

As you can see, I would like to show the release date of a film if I am within that section as I am scrolling.

My code looks like this:

<div class="container">
 <div class="row">
  <div class="span8 offset2">
   <div id="dateNav">
    <ul class="dateNav">
      <li><a href="##{date}"></a><% @response.each_pair do |date, movie| %><%= link_to date_format(date) %><% end %></li>
   </ul>
   </div>
  </div>
 </div>
</div>
<div class="span9">
 <% @response.each_pair do |date, movie| %>
  <h3 class="resultTitle fontSize13" id="<%= date %>">Available on&nbsp;<%= date_format(date) %></h3>
</div>
<!-- More movie information here
<% end %>

I have my body set like so

<body data-spy="scroll" data-target="#dateNav">

and am calling scrollspy like so

$('.dateNav').scrollspy()

When you are in the relevant section the date is supposed to appear

CSS

ul.dateNav ul li a {
 display:none;
}

ul.dateNav ul > li.active > a{
display:block
color: red;
text-decoration: underline;
}

however when scrolling down the page the dates do not appear.

Any help appreciated, would really like to clarify some understanding here.

Thanks

EDIT

ok so have changed as Joe Pym suggested

<li><% @response.each_pair do |date, movie| %><%= link_to date_format(date), "##{date}" %><% end %></li>

Each date has its own id now which wasnt happening before but still no appearance of the relevant date

HTML now generated

<ul class="dateNav">
 <li>
 <a href="#2013-01-09">9th Jan 2013</a>
 <a href="#2013-01-11">11th Jan 2013</a>
 <a href="#2013-01-18">18th Jan 2013</a>
 <a href="#2013-01-23">23rd Jan 2013</a>
 <a href="#2013-01-25">25th Jan 2013</a>
 <a href="#2013-01-30">30th Jan 2013</a>
 </li>
</ul>

EDIT for Sara

calling scrollspy

$('#spyOnThis').scrollspy();

Nav for dates

<div class="container">
 <div class="row">
  <div class="span12">
   <div id="dateNav">
    <ul class="nav dateNav">
      <li><% @response.each_pair do |date, movie| %><%= link_to date_format(date), "#d_#{date}" %><% end %></li>
    </ul>
   </div>
  </div>
</div>

List of Movies

<div id="spyOnThis">
  <% @response.each_pair do |date, movie| %>
    <h3 class="resultTitle fontSize13" id="d_<%= date %>">Available on&nbsp;<%= date_format(date) %></h3>
    <% movie.each do |m| %>
      <div class="thumbnail clearfix">
        <img class="pull-left" src=<% if m.image_link %> <%= m.image_link %> <% else %> "/assets/noimage.jpg" <% end %>>
        <div class="caption pull-right">
          <%= link_to m.name, m.title_id, :class => 'resultTitle fontSize11' %>
          <p class="bio"><%= m.bio %></p>
          <p class="resultTitle">Cast</p>
          <p class="bio"><%= m.cast.join(", ") unless m.cast.empty? %></p>
          <%= link_to "Remind me", reminders_path(:title_id => m.title_id), :method => :post, :class => 'links button' %>
        </div>
      </div>

    <% end %>
  <% end %>
  </div>

CSS

#spyOnThis {
 height:auto;
 overflow:auto;
}

I set height as auto because the number of results can change every time

ul.dateNav > li.active > a {
display:block;
color: red;
text-decoration: underline;
}
  • 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-17T18:07:33+00:00Added an answer on June 17, 2026 at 6:07 pm

    IDs that start with a number are invalid. Source

    Try adding a string constant to the beginning of each ID.

    <a href="#d_#{date}"></a>
    

    and

    <h3 class="resultTitle fontSize13" id="d_<%= date %>">
    

    Disclaimer: I don’t know Ruby.


    EDIT

    Okay, so I stripped this down and got it working. jsFiddle

    I changed some of your classes and IDs for fiddle purposes (also there seemed to be some confusion about .dateNav and #dateNav), but it should look something like this:

    <ul class="nav dateNav">
      <li>
        <a href="#d_#{date}"><% @response.each_pair do |date, movie| %><%= link_to date_format(date) %><% end %></a>
      </li>
    </ul>
    

    and

    <div class="span9">
      <% @response.each_pair do |date, movie| %>
      <h3 class="resultTitle fontSize13" id="d_<%= date %>">Available on&nbsp;<%= date_format(date) %></h3>
    </div>
    

    You can put the IDs on div (like in the fiddle) or h3, it doesn’t matter. The important part is the CSS and how you initiate ScrollSpy.

    If you’re calling it with JavaScript ($('#spyOnThis').scrollspy()), you need to attach it to the element that is going to trigger scroll events – not the menu that keeps track. Source
    Furthermore, you should remove data-spy and data-target from the body element.

    Last but not least, the element you’re calling .scrollspy() on needs to have a height and overflow: auto; set for the plugin to keep track of the scroll position.

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

Sidebar

Related Questions

I am relatively new to Ajax and I am still trying to grasp all
I'm trying to grasp the concept of .NET Generics and actually use them in
I'm trying to grasp a bit of an idea here. And hoping someone can
I am still trying to grasp the finer points of how I can run
I'm trying to grasp more of the cqrs concepts. Are commands only sent from
I'm trying to grasp the idea with build scripts, nightly builds and technologies like
I have been trying to grasp the basics of Support Vector Machines, and downloaded
I am trying to grasp a bit more of buildout with this tutorial ,
I'm trying to grasp the concept of a Batcher Sort . However, most resources
I'm trying to grasp higher-order-polymophism in scala by implementing a very basic interface that

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.