Skip to content

Commit

Permalink
Set default values for group
Browse files Browse the repository at this point in the history
  • Loading branch information
allenwq committed May 29, 2015
1 parent 9768a4e commit 301405d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/course/group.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
class Course::Group < ActiveRecord::Base
stampable

before_validation :set_defaults, if: :new_record?

belongs_to :course, inverse_of: :groups
has_many :group_users, inverse_of: :course_group, dependent: :destroy,
class_name: Course::GroupUser.name, foreign_key: :course_group_id
has_many :users, through: :group_users

private

# Set default values
def set_defaults
return unless creator && creator.courses.include?(course) && group_users.empty?
group_users.build(user: creator, role: :manager, creator: creator, updater: updater)
end
end

0 comments on commit 301405d

Please sign in to comment.