Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CreateEvents < ActiveRecord::Migration
- def self.up
- create_table :events do |t|
- t.string :type
- t.integer :user_id
- t.integer :course_id
- t.timestamps
- end
- end
- def self.down
- drop_table :events
- end
- end
- ##
- class Event < ActiveRecord::Base
- belongs_to :user
- belongs_to :course
- named_scope :current_events, :order => "created_at DESC", :include => [:user, :course]
- end
- ##
- class NewCourseEvent < Event
- validates_presence_of :course_id
- end
- ##
- class NewRegistrationEvent < Event
- validates_presence_of :user_id, :course_id
- end
- ## module EventsHelper
- def event_text(event)
- case event[:type]
- when 'NewCourseEvent' then "#{link_to h(event.course.name), course_path(event.course)} has been added to the course catalog!"
- when 'NewUserEvent' then "#{h(event.user.username)} has joined ilmo!"
- when 'NewRegistrationEvent' then "#{h(event.user.username)} is attending #{link_to h(event.course.name), course_path(event.course)}"
- end
- end
- end
Add Comment
Please, Sign In to add comment