Extras
Optional exercises to expand your Rails blogging app, including navigation, article views, and RSS feed.
Here are some ideas for extending its functionality and learning more about Rails development.
Add a Site-Wide Sidebar
Create a shared sidebar partial with links to key pages like:
- Home
- All Articles
- Popular Articles
- Tags
Then render the sidebar in your main layout (application.html.erb).
Add Date-Based Navigation
Let users browse articles by publication month. Steps:
- Extract the month and year from
created_at. - Group articles by month.
- Create navigation links like:
<%= link_to "June 2025", articles_path(month: "2025-06") %>- Filter results in the
ArticlesControllerbased onparams[:month].
Track Article Views
Add a view_count column to your articles table:
rails generate migration AddViewCountToArticles view_count:integer
rake db:migrateIn article.rb, add a method:
def increment_view_count
self.increment!(:view_count)
endCall it in the show action of articles_controller.rb.
Show Most Popular Articles
After tracking views, you can display the top 3 articles:
@popular_articles = Article.order(view_count: :desc).limit(3)Render this list in a sidebar or homepage widget.
Create an RSS Feed
Rails makes it easy to respond with XML. In your controller:
respond_to do |format|
format.html
format.rss { render layout: false }
endThen create index.rss.builder in app/views/articles/ with:
xml.instruct!
xml.rss version: "2.0" do
xml.channel do
xml.title "My Blog"
xml.description "Latest articles"
xml.link articles_url
@articles.each do |article|
xml.item do
xml.title article.title
xml.description truncate(article.body, length: 100)
xml.pubDate article.created_at.to_s(:rfc822)
xml.link article_url(article)
xml.guid article_url(article)
end
end
end
endVisit /articles.rss to test it!
Keep Exploring
These are just a few enhancements to take your app further. Feel free to experiment and make the app your own!