Wednesday, January 5, 2011

[Rails] 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

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate