Thursday, November 10, 2005

why was that so difficult

okay, so i was thinking way too deep into this whole 5 most recent posts thing. all i had to do was take out the WHERE clause and put a LIMIT 5 on the end.

SELECT id, title FROM posts ORDER BY created_on DESC LIMIT 5

and there you go.

i also added a links table to the database to put links into the menu. for the controller, i added a @links variable and used another find_by_sql statement:

@links = Link.find_by_sql "SELECT name,url FROM links ORDER BY 'name'"

then, of course, i added the code to the index to display them. same kind of loop as the rest of the menu.

for link in @links
<li><a href="<%= link.url %>"><%= link.name %></a></li>
end

0 Comments:

Post a Comment

<< Home