metamaps--metamaps/app/models/message.rb

23 lines
481 B
Ruby
Raw Permalink Normal View History

2016-09-24 03:00:46 +00:00
# frozen_string_literal: true
class Message < ApplicationRecord
2015-12-11 19:23:41 +00:00
belongs_to :user
belongs_to :resource, polymorphic: true
delegate :name, to: :user, prefix: true
after_create :after_created
2015-12-11 19:23:41 +00:00
def user_image
user.image.url
2015-12-11 19:23:41 +00:00
end
def as_json(_options = {})
json = super(methods: [:user_name, :user_image])
2015-12-11 19:23:41 +00:00
json
end
def after_created
ActionCable.server.broadcast 'map_' + resource.id.to_s, type: 'messageCreated', message: self.as_json
end
2015-12-11 19:23:41 +00:00
end