recent posts limited
i found out how to limit the number of recent posts in the menu. there is a find_by_sql function in ruby. i added the following to the index section in the controller:
def index
...
@recent = Post.find_by_sql "SELECT id, title FROM posts where id >= (LAST_INSERT_ID()-4) ORDER BY created_on DESC"
end
before, i was sharing the variable @posts to display the actual post content and also the recent posts links in the menu (@post.title). so i made the @recent variable to use for just the menu and limit the amount of records to the latest 5 in descending order.
0 Comments:
Post a Comment
<< Home