Question

I have created a form for my news articles which I then call to my front page like so

<li class="clearfix">                      
<% @articles.each do |article| %>                       
<h4><a href="#"><%= article.header %></a></h4>                       
<p><%= article.created_at.strftime("%A %d %B %Y ")%></p>                      
<p><%= article.message %></p>                        
<a href="#" class="more">Read more</a>                       
<% end %>                       
</li>

But i want to use something a bit slicker and have come across Jquery Newsticker.

Now the view for this looks like this

  <ul id="js-news" class="js-hidden">    
  <li class="news-item"><a href="#">This is the 1st latest news item.</a></li>   
  <li class="news-item"><a href="#">This is the 2nd latest news item.</a></li>   
  <li class="news-item"><a href="#">This is the 3rd latest news item.</a></li>   
  <li class="news-item"><a href="#">This is the 4th latest news item.</a></li>
  </ul>

What i would like to be able to do is in the first li is call the most recent article created and in the second li call the next recent article and so on up until 4.

I have played around with it a little but all i seem to get is the text appearing at the end of the newsticker, not starting at the beginning

Any advice is appreciated

Était-ce utile?

La solution

I think this is (maybe) what you are talking about.

# Model
scope :recent, order(updated_at: 'DESC')

# Controller
@articles = Article.recent

# Helper
def populate_atricle
  @articles.each do |article|
    content_tag(:li, link_to(article.message, '#'), class: 'news-item')
  end
end

# View
<ul id="js-news" class="js-hidden">
  <%= populate_article %>
</ul>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top