I have seen one solution where the first image in the topic will be used for open graph and twitter tags
But my issue is something different.
I need to provide custom images just as mentioned above, but the image would not be present in the topic content (it will be present in topic custom fields).
I checked the ApplicationHelper class containing
But how do I dynamically set the tags in topic view. I used serialiser to insert
excerpt inside topic, but it had no effect on meta tags.
add_to_serializer :topic_view_ , :excerpt do
# add custom fields to topic view excerpt
If you can even point me to relevant code, it would be helpful, as I am not sure how to use
applicationhelper inside topic serialiser.
If the question was confusing,
I just want to change the meta tags dynamically for open graph ( facebook ) and twitter share.
The serializer is a response in JSON format for an API call. It won’t be used when generating a page’s HTML.
Those tags are using the TopicView model, so you’ll have to extend it using
add_to_class instead of
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?
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