In this article, we consider a solution using the SQL view to avoid query problem N+1 when calculating the average values in Ruby on Rails application.
Tutorial and link to GitHub are available at:
[https://jtway.co/how-to-avoid-n-1-query-using-sql-views-materialized-in-rails-application-7cf415cd112f](https://jtway.co/how-to-avoid-n-1-query-using-sql-views-materialized-in-rails-application-7cf415cd112f)
I just use the bullet gem to find that kind of stuff, much easier: https://github.com/flyerhzm/bullet