1

我为我的新闻文章创建了一个表格,然后我像这样调用我的首页

<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>

但我想使用一些更漂亮的东西,并且遇到了 Jquery Newsticker。

现在这个视图看起来像这样

  <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>

我想做的是在第一个 li 中调用最近创建的文章,在第二个 li 中调用下一篇最近的文章,依此类推,直到 4。

我已经玩了一点,但我似乎得到的只是出现在新贴纸末尾的文字,而不是从开头开始

任何建议表示赞赏

4

1 回答 1

1

我认为这(也许)就是你所说的。

# 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>
于 2012-03-30T12:21:52.517 回答