Laragon

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:

  1. Extract the month and year from created_at.
  2. Group articles by month.
  3. Create navigation links like:
<%= link_to "June 2025", articles_path(month: "2025-06") %>
  1. Filter results in the ArticlesController based on params[:month].

Track Article Views

Add a view_count column to your articles table:

rails generate migration AddViewCountToArticles view_count:integer
rake db:migrate

In article.rb, add a method:

def increment_view_count
  self.increment!(:view_count)
end

Call it in the show action of articles_controller.rb.


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 }
end

Then 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
end

Visit /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!