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 <%= 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 <%= 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;
}