Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 271111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:06:35+00:00 2026-05-12T00:06:35+00:00

Hy guys. I’ve created a simple blog app with the usual CRUD actions. I’ve

  • 0

Hy guys. I’ve created a simple blog app with the usual CRUD actions. I’ve also added a new action in the PostController called “archive” and an associated view. In this view I want to bring back all blog posts and group them by month, displaying them in this kind of format:

March
<ul>
    <li>Hello World</li>
    <li>Blah blah</li>
    <li>Nothing to see here</li>
    <li>Test post...</li>
</ul>

Febuary
<ul>
    <li>My hangover sucks</li>
    ... etc ...

I can’t for the life of me figure out the best way to do this. Assuming the Post model has the usual title, content, created_at etc fields, can someone help me out with the logic/code? I’m very new to RoR so please bear with me 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:06:36+00:00Added an answer on May 12, 2026 at 12:06 am

    group_by is a great method:

    controller:

    def archive
      #this will return a hash in which the month names are the keys, 
      #and the values are arrays of the posts belonging to such months
      #something like: 
      #{ "February" => [#<Post 0xb5c836a0>,#<Post 0xb5443a0>],
      # 'March' => [#<Post 0x43443a0>] }
      @posts_by_month = Posts.find(:all).group_by { |post| post.created_at.strftime("%B") }
    end
    

    view template:

    <% @posts_by_month.each do |monthname, posts| %>
    <%= monthname %>
    <ul>
       <% posts.each do |post| %>
         <li><%= post.title %></li>
       <% end %>
    </ul>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

guys. I have a strange problem. I try to write unit-tests to web-app. I
Guys, what is function called after my class loaded, where i can call self
guys. In our project, we need to add a new feature which is to
Guys, I am very new to c++. I have just wrote this class: class
guys. I'm pretty new to both Silverlight and WCF. What I'm trying to do
Guys I am new to Windows Phone Development in .Net Can any one guide
Guys i am new to programming and i am really not aware of how
guys i am thinking about one sorting method,it is called sleep sort #include <stdlib.h>
Guys if we request a site on a server along with some images also
Guys, I'm quite new to extJS and I would like your help. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.