Rails Best Practices
slideshare.net
slideshare.net
Actual examples from my code base:
@word_list = @user.word_lists.find(params[:wl])
versus the alternative (of which there are multiple variations):
@word_list = WordList.find(params[:wl], :conditions => {:user_id => @user})
This will work fine... right until one of your programmers forgets to put that condition statement in there. Then, you'll allow folks arbitrary access to other people's data, silently. I have seen a lot of Rails code that guards against this by checking access before critical actions -- again, this will work fine until you forget to do it. Instead, establish the convention that you only instantiate the model objects through something which guarantees authorization, and then the existence of the model object is proof that access to it is authorized. (Adjust as required if you work in banking or state secrets. I write bingo cards for a living.)
It's amazing how many projects I run across that completely lack proper indexing. Many lack any indexes at all. It's almost like db:migrate should warn you if you've run a migration that lacked any indexes.
Rails makes it so easy to forget about the database (yes, I'm talking about you database constraints in the actual database), that users often forget that it can be a pretty important piece of their application (especially when it gets popular).
I hope this will be republished as a text article sometime, because that would make referring to the code examples easier.
Very thoughtful presenation.
The often suggested use for observers is for caching (which is a good example). In our big app, if the cache expiry doesn't happen the site will look a bit funny but the underlying transactional data is fine. Mixing those together wouldn't communicate the difference in how important they are.