Allows you to split your ActiveRecord find calls and your eager loading decisions.
Add this line to your application's Gemfile:
gem 'preload'
And then execute:
$ bundle
Or install it yourself as:
$ gem install preload
Now in your controller you don't have to know which associations should be eager loaded because your views need them.
def index
@posts = blog.posts.all(:order => 'created_at DESC')
end
<% @posts.preload(:comments) %>
... render posts and their comments ...
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request