Benito Serna Helping you be better with Ruby on Rails

Weekly tips and articles for Ruby on Rails developers

Making things work isn't enough for you any more? Now you need to consider performance and scalability?

Do you hope to some day come with efficient solutions by yourself rather than stumble on many stackoverflow questions to get something done?

Do you feel unqualified to tackle complex tasks with complex data models?

Do you feel that you need to sharpen your sql/active record concepts?

Maybe I can help you!

I send an email each week, trying to share knowledge and fixes to common problems and struggles for ruby on rails developers, like How to fetch the latest-N-of-each record or How to test that an specific mail was sent or a Capybara cheatsheet. You can see more examples on Most recent posts or All post by topic.

Most recent posts

  • Preload object on the guide for preloading associations

    I want to tell you that I have added a new section to the guide for preloading associations in rails, to introduce you to something I call “Preload objects” that will help you build complex preloads for those cases when you can’t find a way to do what you need to do, with the standard rails mechanisms.

    Read more

  • Using an objet to represent a complex preload

    Sometimes just using preload or includes is not possible… or maybe it is, but you just can’t figure it out how to do it.

    Maybe you want to preload some records matching two keys, or preload a grouped relation.

    Maybe you know how to represent the association with a has_many :through, but you need something faster, or to use less memory.

    In that kind of situations, one thing that you can do is to write a custom object to represent that preload.

    Here I will try to explain how and when you can do it with an example.

    Read more

  • A guide for preloading associations in rails

    Maybe you are already familiar with includes or preload, but you know that a lot of the time you will need more than just preload(:comments).

    It is common to have complex nested associations, scopes that you need or want to reuse, places where preloading all the associated records could hurt the performance of your app.

    How do you work with complex nested associations?… How do you simplify the preloading of those nested associations?… How do you “preload an scope”?… How do you preload just the latest n of each record?

    Read more

  • What is an n+1 queries problem?

    An n+1 queries problem means that a query is executed for every result of a previous query.

    For example, with this records…

    class Post < ActiveRecord::Base
      has_many :comments
    class Comment < ActiveRecord::Base
      belongs_to :post

    If you...

    Read more
  • Tool to run the examples for the 5 ways to fetch the latest-n-of-each record

    A common cause of n+1 queries is fetching the “latest-N-of-each” record on a list of records.

    Some examples of this problem are trying to get…

    Read more

All post by topic