@ -7,22 +7,24 @@ class Poll < ActiveRecord::Base
has_many :poll_users , :dependent = > :destroy
has_many :users , :through = > :poll_users #该文件被哪些用户提交答案过
# 添加课程的poll动态
# has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
# after_create :act_as_activity
has_many :acts , :class_name = > 'Activity' , :as = > :act , :dependent = > :destroy
after_create :act_as_activity
# acts_as_event :title => Proc.new {|o| "#{l(:label_my_message)} ##{o.id}: #{o.name}" },
# :description => :description,
# :author => :author,
# :url => Proc.new {|o| {:controller => 'poll', :action => 'show', :id => o.id}}
acts_as_event :title = > Proc . new { | o | " #{ l ( :label_course_poll ) } : #{ o . polls_name } " } ,
:description = > :polls_description ,
:datetime = > :published_at ,
:author = > :user ,
:url = > Proc . new { | o | { :controller = > 'poll' , :action = > 'show' , :id = > o . id } }
# acts_as_activity_provider :type => 'polls',
# :permission => :view_course_polls,
#:find_options => {:include => [:course, :author]},
#:timestamp => "#{self.table_name}.published_at",
# :author_key => :author_id
acts_as_activity_provider :type = > 'polls' ,
#:permission => :view_course_polls,
:find_options = > { :select = > " #{ Poll . table_name } .* " ,
:joins = > " LEFT JOIN #{ Course . table_name } ON ( #{ Poll . table_name } .polls_type='Course' AND #{ Poll . table_name } .polls_status= 2 AND #{ Poll . table_name } .polls_group_id = #{ Course . table_name } .id ) " } ,
:timestamp = > " #{ self . table_name } .published_at " ,
:author_key = > :user_id
# def act_as_activity
# self.acts << Activity.new(:user_id => self.user_id )
# end
def act_as_activity
self . acts << Activity . new ( :user_id = > self . user_id )
end
end