我做一个文章发表的系统,数据库中有表posts(id,title,content).
controller中定义了文件:post_controller.rb,其中有方法:
ruby 代码
- def list
- @post_pages, @posts = paginate :posts, :per_page => 5
- end
在Views中的 list.rhtml中通过以下代码显示:
ruby 代码
- <% for post in @posts %>
- <h3>
- <%=post.title %>
- </h3>
- <%=(post.content)[0..200] %>
- <br/>
- <%= link_to 'Show', :action => 'show', :id => post %>
- <%= link_to 'Edit', :action => 'edit', :id => post %>
- <%= link_to 'Destroy', { :action => 'destroy', :id => post }, :confirm => 'Are you sure?', :method => :post %>
- <hr/>
- <% end %>
我希望的是数据表中的数据逆序输出,怎么办呢?