新手问题 取数据

rubyway · 2012年09月24日 · 最后由 rubyway 回复于 2012年09月24日 · 1884 次阅读

rails 取出当前文章的上一篇和下一篇文章怎么做?

你需要 SQL 查询

select * from posts where id > 100  limit 1
select * from posts where id < 100 limit 1

ActiveRecord 里面

Post.where("id > 100").limit(1).first
Post.where("id < 100").limit(1).first
需要 登录 后方可回复, 如果你还没有账号请 注册新账号