Record count from different table

I am trying to count the number of questions in each subject and then
display the question count for each subject next to the subject name:

Subject Model
has_many :questions

Controller
def index
@subjects = Subject.order(:title)
@question_number = Question.find(???).count

View
<% @subjects.each do |subject| %>
<%= subject.title %> (<%=@question_number %>)

The questions table has a subject_id attribute and this is what I want
to query on

Best way to find the count for each subject in the @subjects
hash and then display with the associated subject?

Dave

Thanks, was overthinking it!

Dave

On Sat, Sep 22, 2012 at 8:04 AM, Dave C. [email protected]
wrote:

I am trying to count the number of questions in each subject and then
display the question count for each subject next to the subject name:

<%= subject.title %> (<%=
@question_number %>)

Can’t understand how to find the count for each subject in the @subjects
hash and then display with the associated subject

<%= subject.questions.count %> doesn’t work?


Hassan S. ------------------------ [email protected]

twitter: @hassan