views:

15

answers:

2

Hi all,

I'm developing an application in which a Course belongs to a user. I would like to predefine a number of courses, such that a Course's template details are then copied into the users course details. From this initial point each user has a one-to-one mapping with a course.

I'd like to know the best place for the static attributes for building a user's course.

Thanks, Adam

+1  A: 

You could use a before_create or after_create filter on your user model, something like this:

before_create :add_default_courses

def add_default_courses
  self.courses << Course.new({:foo => 'bar'});
end
Daniel Mendel
A: 

you can initialize courses after a user is created.

User.rb #you user file

def after_initialize
    self.courses << add_courses
end

private

def add_courses
    @add_courses = Courses.find(:all, conditions => [])
end
Sam