occasionally useful ruby, ubuntu, etc

24Jul/120

Quick Start with Sequel 3 in Rails 3

This guide is using Rails 3.2.6 and Sequel 3.37.0. If you're using a different version, these instructions may not quite apply.

Edit: realized this morning the title was ambiguous, so I updated it to reflect the Sequel focus.

Here's the easiest way to get going with Sequel in Rails:

8Mar/090

Gotcha with Sequel and Association Caching

One thing to remember with Sequel is that it caches associations -- for an hour, by default. Normally this is good -- if I say my_model.my_associated_models twice in one request, I'd like that to be cached. But at least with Ramaze, where you can access a variable that persists between requests (via session, like session[:user]), you have to remember that associations on that session object get cached, too. So what does that mean? That means if you have a user view their posts (with session[:user].posts), and then they go make a post, and then they come back to view their posts again...the new post won't be in the list of posts! So you have two basic options here, that I know of -- either a) manually kill the cache by putting session[:user].refresh on the action that alters the associations of session[:user], or b) put session[:user].refresh in a place that gets executed at the beginning of every request.

Filed under: ramaze, ruby, sequel No Comments