Medium Feed Integration on Rails App
How to get your stories to show up in your Rails Site
Recently I was working on AlturaSoluciones’ new website and we needed to add a Medium feed to the page so the visitors could see the recent articles that the company has published on this platform. After searching and trying various solutions I came up with a mix of two or three of them and I want to share the final result with you so you can add your Medium feed on your Rails site as well.
Getting your Medium RSS Feed URL
According to the oficial docs of Medium:
Medium provides RSS feeds for user profiles and publications. User profile To access a user's feed, add /feed/ before…help.medium.com
Medium provides feed for users and publications:
To access a user’s feed, add
/feed/ before their username: medium.com/feed/@Medium
For a Medium publication’s RSS feed, add
/feed/ before the publication's name, like so: medium.com/feed/the-story
For a publication on a custom domain, add
/feed to the end of the URL: https://journal.thriveglobal.com/feed.
But we need to process this xml because right know we only get something like this from the feed url:
Implementing the Helper method in Rails
On my app I created a new helper in
lib/medium_news_helper.rb. There I added the following method to retrieve the elements of the feed and return them to the view:
On line 1 we declare the helper module. We are using
open-uri libraries to handle and parse the RSS Feed on line 2–3. On line 6–11 we implement our method taking the first 7 elements and iterate through them returning an array of objects with the structure described on line 9.
Rendering on the view
Lastly we need to render that information on the landing page. For that we add the following code on the
Don’t mind the html clases and ids that are only used to style the content. The important part is from line 4–13.
On line 4 we call our helper method that returns an array of objects an iterates through each element. For each element we generate a line with the article number(incremental), the author name, and the title with a link to the Medium post.
We also add this line to let the user navigate to our Medium blog page or publication:
I hope this article was helpful and you can use it to integrate your Medium Feed into your Rails website. With some modifications this can be adapted to other technologies. Feel free to do it and post your solution as comment or create your own article.
If you have any question let me know or leave a comment.
Author: Eng. Alberto Aragón Alvarez
If you like it, clap. For more histories like this one follow our publication on Medium or subscribe to our mailing list.