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 4029536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:21:27+00:00 2026-05-20T11:21:27+00:00

So I have a forum application and double nested resources. Section–>Topic–>Replies and are set

  • 0

So I have a forum application and double nested resources. Section–>Topic–>Replies and are set up as such in the application controller (Rails 3 style). I’m looking at the section view and am trying to sort my topics. In most forums the most logical sorting method is by when it’s updated last. This would be simple if it was just by replies. The obvious problem is, there are topics without replies, so sorting simply by replies won’t work.

            <% @section.topics.sort_by{ ?? }.each do |topic| %>
              <tr>
                <td class="topic"><%= link_to topic.subject, [@section, topic] %></td>
                <td class="postCount"><%= topic.replies.count %></td>
                <td class="date">
                <% if topic.replies.empty? %>
                  <%= topic.created_at.strftime("%I:%M%p %m/%d/%y") %>
                <% else %>
                  <%= topic.replies.last.created_at.strftime("%I:%M%p %m/%d/%y") %>
                <% end %>
                </td>
              </tr>  
            <% end %>

So basically if the replies are empty, you pull when the topic was created. If there are replies, pull when the last one was created. This displays wonderfully in the show sections view, but I have no clue how to sort using this.

I tried making a method in the topic model called “last_updated”. I wrote it like:

  def last_update(sectionTopic)
if sectionTopic.replies.empty?
  return sectionTopic.created_at
else
  return sectionTopic.replies.last.created_at
end

end

And passed it in through the view:

<% @section.topics.sort_by{ |topic| topic.last_update(@section.topics)}.each do |topic| %>

But I get a undefined method `replies’ when I do this. Any ideas? Thank you.

  • 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-20T11:21:27+00:00Added an answer on May 20, 2026 at 11:21 am

    From what I can tell,

    topic.last_update(@section.topics)
    

    should be:

    topic.last_update(topic)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im creating forum like application and I have textbox where users can enter tags
I have a Rails 3.1 application where the view has the following link: <%=
I have a windows form application. On the form there are three groupboxs. Each
I have a Windows Form application. Version 1 of my app has been released
I have a Windows form application that's consuming web services over https and is
I have an C# form application that use an access database. This application works
I have a Windows Form application with a button named loginBtn and a label
Windows form application(.Net 3.5) I have a textbox and a button on the form.
I have a form in my application that will fill using Unicode characters (Non
I have a C# Windows Form application that contains a menu with this event:

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.