Guest User

Untitled

a guest
Jul 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class CreateEvents < ActiveRecord::Migration
  2. def self.up
  3. create_table :events do |t|
  4. t.string :type
  5. t.integer :user_id
  6. t.integer :course_id
  7. t.timestamps
  8. end
  9. end
  10.  
  11. def self.down
  12. drop_table :events
  13. end
  14. end
  15.  
  16. ##
  17.  
  18. class Event < ActiveRecord::Base
  19. belongs_to :user
  20. belongs_to :course
  21.  
  22. named_scope :current_events, :order => "created_at DESC", :include => [:user, :course]
  23. end
  24.  
  25. ##
  26.  
  27. class NewCourseEvent < Event
  28. validates_presence_of :course_id
  29. end
  30.  
  31. ##
  32.  
  33. class NewRegistrationEvent < Event
  34. validates_presence_of :user_id, :course_id
  35. end
  36.  
  37. ## module EventsHelper
  38. def event_text(event)
  39. case event[:type]
  40. when 'NewCourseEvent' then "#{link_to h(event.course.name), course_path(event.course)} has been added to the course catalog!"
  41. when 'NewUserEvent' then "#{h(event.user.username)} has joined ilmo!"
  42. when 'NewRegistrationEvent' then "#{h(event.user.username)} is attending #{link_to h(event.course.name), course_path(event.course)}"
  43. end
  44. end
  45. end
Add Comment
Please, Sign In to add comment