Ad Richards wrote:
> I have got as far as making it so that a grade field is automatically
> created for each new assignment:
>
> def create
> @assignment = Assignment.new(params[:assignment])
> @gradation = @assignment.gradations.build(params[:gradation])
>
> But I don't know how to pass the student id in so that a new grade field
> is created for each and every existing student...
I would think that you could do something like (pardon the sparsity, but
I cobbled this together over lunch):
class Course < ActiveRecord::Base
has_many :enrollments
has_many :students, :through => :enrollments
has_many :assignments
has_many :gradations, :through => :assignments
validates_presence_of :name
end
class Student < ActiveRecord::Base
has_many :enrollments
has_many :courses, :through => :enrollments
# not positive this works through this many levels, but conceptually
has_many :assignments, :through => :courses
has_many :gradations, :through => :assignments
validates_presence_of :first_name, :list_name
end
class Enrollment < ActiveRecord::Base
belongs_to :student
belongs_to :course
validates_presence_of :student_id, :course_id
end
class Gradation < ActiveRecord::Base
belongs_to :assignment
belongs_to :student
validates_presence_of :assignment_id, :student_id
end
class Assignment
belongs_to :course
has_many :gradations
validates_presence_of :course_id
after_create :build_gradations
def build_gradations
self.course.students.each do |student|
Gradation.create(:assignment_id => self.id, :student_id =>
student.id)
end
end
end
When I create an assignment for a course, the gradations are built for
each student currently associated with the course.
A grading process could start from choose a course, choose the
assignment, then present the list of students and their grades (I'd
allow for grade edits because, well, it happens).
Or something like that... late for a meeting at the moment, so gotta
run.
--
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---