Dynamic open graph and twitter images in meta tags of topic page when image is not present in topic

Thank you @eviltrout. I am still learning ruby, but what I understand is I have to override the summary method in TopicView class (using add_to_class, as you suggested), change the excerpt to my own string containing img tag. Is my understanding correct?

def summary
    return nil if desired_post.blank?
    # TODO, this is actually quite slow, should be cached in the post table
    excerpt = desired_post.excerpt(500, strip_links: true, text_entities: true)
    (excerpt || "").gsub(/\n/, ' ').strip
  end