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

  • Home
  • SEARCH
  • 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 8223583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:45:19+00:00 2026-06-07T14:45:19+00:00

I have 2 attributes opening_date and closing_date in a Tender model. On the index

  • 0

I have 2 attributes opening_date and closing_date in a Tender model. On the index page what I display is the remaining date which is (closing_date-Date.today). However, remaining date is not saved in a database but I wanted to order and display the data in the table by remaining date. What should I use? Is there an aggregate function for that?

I am using Ruby 1.9.2 and Rails 3.2.2

//TendersController

 def index
 @tenders= Tender.where("company_id= ? ", current_user.company.id).order('closing_date') 
/* Here I am querying the tender by closing_date but I dont want to do that. What I wanted is I just want to order by (closing_date-Date.today) which is not in the database but should be done on the fly. i.e the smallest the number it should be at the top of the table (index.html.erb) to notify the user the closing date is sooner than they think
*/
end

//Tender Model

attr_accessible :title, :buyer_name, :category, :opening_date, :closing_date, :bid_amount, :description, :status

//index.htm.erb

<table border="1" id="tender_table" >
  <tr class="table_header">
    <th>Title</th>
    <th>Buyer Name</th>
    <th>Remaining dates</th>
    <th>Status</th>
    <th>Bid amount</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

  <% @tenders.each do |tender| %>
<% day_diff= tender.closing_date.to_date-Date.today %>
<tr class=<%= tender.status %>> 
<td><%= tender.title %></td>
    <td><%= tender.buyer_name %></td>
    <td >

        <%  if day_diff < 0 %>
        <FONT COLOR="black"><%= -(day_diff).to_i %> days passed</td>

        <% else if day_diff > 10%>
            <FONT COLOR="green"><%= distance_of_time_in_words(tender.closing_date,Date.today) %></td>                   

        <% end %>
        <% end %>

        <% if day_diff <= 10 and day_diff>=0 %>
                <FONT COLOR="red"><%=distance_of_time_in_words(tender.closing_date,Date.today)+' ' %>left</td>

        <% end %>





    <td><%= tender.status %></td>
    <td><%= tender.bid_amount %></td>


    <%#  tender.description %>

    <td><%= link_to 'Show', tender %></td>
    <td><%= link_to 'Edit', edit_tender_path(tender) %></td>
    <td><%= link_to 'Destroy', tender, confirm: 'Are you sure?', method: :delete %></td>
  </tr>
<% end %>
</table>
  • 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-06-07T14:45:22+00:00Added an answer on June 7, 2026 at 2:45 pm

    You could use sort_by, but that’s on the ruby side and therefore slow on large datasets (the database should handle that). Use closing_date > NOW() and an :order_by.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of attributes which can be either NOP or have a
I have a series of attributes that either are, or are not, applied to
I have the following filter: open_slots = Opening.objects.filter(club_id=club_id, day=datetime.date.today(), reservation ='Open') I want to
I have a model named Store . In this I have attributes such as
I have few element in my html page which has tabIndex attribute. Now I
I have 2 attributes that I use within the controllers of my MVC application.
I have quite a lot of music files but their title attributes have the
I have a component with a number of properties that have various attributes Normally
In trying to select elements that have any attributes, the following throws a jQuery
I've seen in a few iPhone examples that attributes have used an underscore _

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.