Advertisement
Guest User

Untitled

a guest
May 30th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.48 KB | None | 0 0
  1.     t.integer  "user_id"
  2.     t.text     "message"
  3.     t.datetime "created_at"
  4.     t.datetime "updated_at"
  5.     t.integer  "pitch_id"
  6.     t.integer  "activity"
  7.     t.integer  "parent_id"
  8.     t.integer  "activitable_id"
  9.     t.string   "activitable_type"
  10.     t.integer  "status",           default: 1
  11.  
  12.  
  13.  
  14.   belongs_to  :user
  15.  
  16.   belongs_to  :activitable,
  17.               polymorphic: true
  18.  
  19.   has_many  :comments,
  20.             -> { approved.order(created_at: :desc) },
  21.             class_name: 'Activity',
  22.             foreign_key: 'parent_id'
  23.  
  24.   def message
  25.     return self[:message] || "" if activity==0 || (activitable.nil? && activity!=1) || (activity==5 && !activitable.is_a?(Crowdfunding))
  26.     begin
  27.       case activity
  28.       when 1
  29.         "Joined on #{l user.created_at, format: :dayMonYear}."
  30.       when 2
  31.         "Has connected his account with #{link_to activitable.provider.humanize.titlecase, activitable.profile_link || (activitable.get_profile_link && activitable.profile_link) || "#", target: '_blank'}"
  32.       when 3
  33.         "Is now following #{link_to activitable.title, activitable, target: '_blank'}"
  34.       when 4
  35.         "Is now following #{link_to activitable.profile.selected_name, activitable.profile, target: '_blank'}"
  36.       when 5
  37.         "#{activitable.pitch_type==0 ? 'Backed' : 'Invested in'} #{activitable.pitch.title}."
  38.       when 6
  39.         "Published new investment opporunity #{activitable.pitch.title}"
  40.       end
  41.     rescue
  42.       nil
  43.     end
  44.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement