Skip to content

Instantly share code, notes, and snippets.

@ahoward
Last active January 2, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ahoward/8285714 to your computer and use it in GitHub Desktop.
Save ahoward/8285714 to your computer and use it in GitHub Desktop.
SEE a.md in this gist

recently our team had an exchange about lazy evaluation of ORM queries in ruby ( https://gist.github.com/ahoward/8285529 ) - this prompted me to think about how deep rails has really become and just how hard good MVC organization for the web really is. back in the day it took a special kind of developer to understand how to not kill a db when it was used in a web app - now it's pretty easy and, while this seems good on the outside, in the inside i think today's developers understand less and less about why web programming is really the hardest kind there is.

that's the motivation for today's quiz. to take it fork and keep your answer under 142 LOC total

given a model, Post, write code which will

  • load the 2nd set of 5 results (page 2 of 5 each)
  • access them in the view

sounds easy right? now here are the requirements:

  • do NOT load any more objects from the db than required - not a single one.
  • no database activity must occur if the view doesn't require it, none.
  • you may not rely on cache helpers, rails, imaginary, or otherwise
  • you many not rely on magic ORB behavior such as lazy evaluation

this is obviously a web developer 101 task - so think about the difficulty in the context of your next framework evaluation (aka when you think writing an api for backboone seems 'easy')

class PostsController
# go
end
class Post
# go
end
<!-- go -->
<%= @posts %>
<ul>
<li> ... </li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment