Module: Survey::ActiveRecord::ClassMethods

Defined in:
lib/survey/active_record.rb

Instance Method Summary collapse

Instance Method Details

#acceptable_attributes(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/survey/active_record.rb', line 15

def acceptable_attributes(*args)

  self.const_set('AccessibleAttributes', args + [:id, :_destroy])

  in_rails_3 do
    if defined?(self.respond_to?(:attr_accessible))
      attr_accessible(*self.const_get('AccessibleAttributes').map { |k| k.is_a?(Hash) ? k.keys.first : k })
    end
  end

end

#has_surveysObject



6
7
8
9
10
11
12
# File 'lib/survey/active_record.rb', line 6

def has_surveys
  has_many :survey_tentatives, as: :participant, :class_name => ::Survey::Attempt

  define_method("for_survey") do |survey|
    self.survey_tentatives.where(:survey_id => survey.id)
  end
end