Showing only Objects from the past 30 days

Viewed 7800

Having finally manage to get my app to list jobs under specific dates. I am now looking to find a way to only show jobs created within the past 30 days.

At the moment my method for showing jobs sits in a partial and looks like this:

 <% @jobs.group_by{|x| x.created_at.strftime("%d %b. %Y")}.each do |date,jobs_on_that_date| %>

 <section class="date">
   <%= date %>
 </section>

 <section id="top-job">
   <% jobs_on_that_date.each do |job| %>
    <section id="job-wrapper">
      <%= link_to url_with_protocol(@link.job_url), :target => '_blank' do %>
      <section id="job">
        <%= job.title %> - <%= job.company %>
        <%= job.salary %>
        <%= job.location %> 
        <%= job.job_type %>
    </section>
 </section> 
<% end %>
 <% end %>
 </section>
 <% end %>

Is there way to integrate only showing the past 30 days worth of jobs in the view or would it be better to define this in the controller?

Thanks!

2 Answers
Related