我做一个文章发表的系统,数据库中有表posts(id,title,content).

controller中定义了文件:post_controller.rb,其中有方法:

ruby 代码
  1. def list   
  2.    @post_pages@posts = paginate :posts:per_page => 5   
  3.  end  

在Views中的 list.rhtml中通过以下代码显示:

ruby 代码
  1. <% for post in @posts %>   
  2.     <h3>   
  3.     <%=post.title %>   
  4.     </h3>   
  5.     <%=(post.content)[0..200] %>   
  6.     <br/>   
  7.     <%= link_to 'Show', :action => 'show', :id => post %>   
  8.     <%= link_to 'Edit', :action => 'edit', :id => post %>   
  9.     <%= link_to 'Destroy', { :action => 'destroy', :id => post }, :confirm => 'Are you sure?', :method => :post %>   
  10. <hr/>   
  11. <% end %>  

 

我希望的是数据表中的数据逆序输出,怎么办呢?

评论
9esuLuciano 2007-09-17
ruby 代码
  1. def list       
  2.    @post_pages@posts = paginate :posts:per_page => 5  ,:order=>'id DESC'   
  3.  end    




发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

kenrome
搜索本博客
博客分类
最近加入圈子
存档
最新评论