2007-09-16
关于Rails开发之数据排序问题
我做一个文章发表的系统,数据库中有表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 %>
我希望的是数据表中的数据逆序输出,怎么办呢?
评论
9esuLuciano
2007-09-17
ruby 代码
- def list
- @post_pages, @posts = paginate :posts, :per_page => 5 ,:order=>'id DESC'
- end
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 1451 次
- 性别:

- 来自: 成都

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
关于Rails2.0下的File-Col ...
pure 写道<%= image_tag url_for_file_col ...
-- by distortion -
关于Rails2.0下的File-Col ...
<%= image_tag url_for_file_column 'gr ...
-- by pure -
升级到Rails2.0 ,出现HT ...
看看log里怎么说。
-- by ashchan -
rails中scaffold自动生成 ...
找到了,修改views的_form.rhtml
-- by kenrome -
rails中scaffold自动生成 ...
kenrome 写道<p><strong>目标:做一个博客系统,有两 ...
-- by 9esuLuciano






评论排行榜