Permalink
Browse files

Reducing the number of queries

  • Loading branch information...
1 parent fc069c0 commit f953e967c7bee3814c9f78c04e313e95e9c5b449 @anthonylewis committed Jul 15, 2011
Showing with 2 additions and 2 deletions.
  1. +1 −1 app/controllers/questions_controller.rb
  2. +1 −1 app/views/questions/index.html.erb
@@ -5,7 +5,7 @@ class QuestionsController < ApplicationController
# GET /questions.xml
def index
@search = Question.search params[:search]
- @questions = @search.paginate :page => params[:page], :per_page => 5
+ @questions = @search.paginate :include => [:answers, :user], :page => params[:page], :per_page => 5
respond_to do |format|
format.html # index.html.erb
@@ -13,7 +13,7 @@
<% @questions.each do |question| %>
<p><%= question.body %></p>
<p><i>By <%= question.user.email %></i></p>
- <p><%= pluralize question.answers.count, 'answer' %></p>
+ <p><%= pluralize question.answers.length, 'answer' %></p>
<p>
<%= link_to 'Show', question %>

0 comments on commit f953e96

Please sign in to comment.