July 12, 2011
at 15:39 PDT
At several points in my career as a Rubyist, I’ve run into situations where I need to store a set of attributes and be able to determine when they have changed. This is actually a fairly common problem, so here are a few common use cases for it:
- You have a managed ORM model with a set of attributes, but you also need a way to store a schemaless set of additional attributes (i.e. they will be different for different instances of the model)
- You have a managed ORM model with a set of attributes that you don’t want to store in your relational database, and you’d like to build a hybrid model that allows you to store them in a NoSQL store
- You aren’t using an ORM or DRM, but have some attributes on a class you need to store in a relational or non-relationsl database and want to see …
read more
Tags:
ruby
|
databases
|
nosql
January 08, 2010
at 14:09 PST
I talked about how to use yield more effectively (and more often) in your Rails apps in a previous post. Over the holidays, I didn’t really have time to write a new post, but I was asked a question that I think merits a little bit of attention.
A curious problem
The question itself was whether there’s a way to tell a view not to use a fragment cache that’s part of a partial being used. The short answer is that you can’t do that. I can think of at least two approaches you can take to get the same result, either by using partials (and perhaps even nesting them) or through more effective use of yield.
The most common way to do this is to use a conditional in the partial. It …
read more
Tags:
rails
|
caching
|
ruby
December 22, 2009
at 14:33 PST
So you’re designing a Rails-based site that you hope will have lots of traffic. While there are certain dynamic elements on every page, most of the content remains fairly static (i.e. it’s read as-is more than it’s changed), and you don’t see the need to waste computing resources on rendering the page for every page view. I’ve been asked about this specific pattern several times, and even when I was looking at what other people had done and figuring out how to do it myself, I never did find a post that really explained what I was supposed to do and how to do it, in any sort of context that helps.
We all know that a static HTML page is super-fast to load, unless it’s overly laden with assets or is excessively long. Rendering a page through the entire application stack takes many times …
read more
Tags:
rails
|
caching
|
jquery
|
javascript
December 11, 2009
at 20:13 PST
It’s nothing new in the Rails world that yield can accept a symbol as an argument, allowing you to use content_for to provide that content from any partial or view. Unfortunately, it’s not clear to a lot of newer Rails developers (and even some older ones…let’s be honest) when that makes more sense than partials. In this article, we’re going to investigate the reasons why you probably want to use yield more than you do, and a couple of common patterns for using yield. Just a quick note before we get into it, though: all the examples will use HAML, since it’s shorter and more readable than ERB.
When should I yield instead of rendering a partial?
Unless you understand how yield and content_for work, it’s hard to know when yield is a better fit than just a simple …
read more
Tags:
rails
December 09, 2009
at 19:18 PST
Whether you’re trying to avoid spam, trying to make sure your accounts are being created by humans, or just want to make sure the users of your site can read (or understand spoken English, in some cases), these days you’ve probably either already implemented, or at least considered, a CAPTCHA validation. At the very least, you’ve interacted with one along the way.
I’ll tell you right now that this post isn’t going to go into frightening technical detail on how to implement a CAPTCHA. There are some other great posts on the topic, along with posts on why particular methods are better than others and why some CAPTCHAs are better than others. I will, however, give you an overview and make the technology seem a lot more accessible.
What’s a CAPTCHA?
Let’s start off by expanding …
read more
Tags:
captcha
|
rails
|
spam