undefined method `model_name' for ActiveRecord::Relation:Class

Greetings, I'm trying to create a spreadsheet using ekuseru.

I have a form that a user enters a course number in and submits. Like 'HA2211'. The action in my controller this goes to is course_enrollment. The view is course_enrollment.xls.eku.

My controller: (in part) class Sso::ReportsController < ApplicationController   respond_to :html, :xls

  def course_enrollment     # create vars long_nbr, short_nbr, ten_semesters_ago from paras[:course] sent from form     long_nbr = params[:course].slice(2,4)     short_nbr = params[:course].slice(3,3)     ten_semesters_ago = ''     if CourseTaken.last_semester == 20       ten_semesters_ago = (Time.now.year-5).to_s + '20'     else       ten_semesters_ago = (Time.now.year-6).to_s + '70'     end     @students = CourseTaken.students_enrolled_in_course(long_nbr, short_nbr, ten_semesters_ago)     if !@students.nil?       respond_with @students, :format => :xls   end end

The error I get is: undefined method `model_name' for ActiveRecord::Relation:Class app/controllers/sso/reports_controller.rb:33:in `course_enrollment'

Line 33 in my controller is:

respond_with @students, :format => :xls

I have a correctly named view: course_enrollment.xls.eku

I've tested and verified via my console the line:

@students = CourseTaken.students_enrolled_in_course(long_nbr, short_nbr,

ten_semesters_ago) This works and @students is not nill.

I do pretty much the same thing in another action for another spreadsheet report and it works fine. I've searched and googled but cannot find what my problem might be.

Thoughts? Thanks for any tips or pointers. JohnC

Can you show the code for the CourseTaken.students_enrolled_in_course method?

Thanks for looking at my problem. I hope this is what you need.

I am using a named_scope (or just scope - rails 3):

scope :students_enrolled_in_course, lambda { |*args| {               :conditions => ["crs_key > ? AND                                final_gr IS NOT NULL AND                                (crs_id in (?,?) AND                                crs_coll in ('HA','HO') AND                                substr(crs_id,3) in                                (SELECT crs_link FROM sso.courses WHERE crs_no in (?, ?)))",                                  args[2], 'HA'+args[1].to_s, 'HA'+args[0].to_s, 'HA'+args[0].to_s, 'HA'+args[1].to_s ],               :order => "crs_key"   }}

The resulting sql this results in is thus: SELECT "SSO"."STCD2_COURSES".* FROM "SSO"."STCD2_COURSES" WHERE (crs_key

200620 AND

final_gr IS NOT NULL AND (crs_id in ('HA211','HA2211') AND crs_coll in ('HA','HO') AND substr(crs_id,3) in    (SELECT crs_link FROM sso.courses WHERE crs_no in ('HA2211','HA211')))) ORDER BY crs_key

I've run this in our Oracle DB and I get 500+ records.

Thanks.