ruby - Only Display Current Month Data -


i have created functioning e-commerce platform members can buy songs , index page organizes data month. works fine, strictly display information current month. (in our case june).

currently able list every month's data, can become problem display when million of songs being bought throughout year.

how can display current months data?

controller

def index   @orders = order.find(:all, :order => 'order_date, id') end 

view

###how can display current month? <% @orders.sort.group_by { |order| order.order_date.beginning_of_month }.each |month, orders| %>   <h3><%= month.strftime('%b') %> </h3>    <% orders.group_by { |order| order.song.album.artist }.each |artist, orders| %>     <h4><%= artist.name %> </h4>      <% orders.group_by { |order| order.song.album }.each |album, orders| %>       <h5><%= album.name %> </h5>          <% orders.group_by { |order| order.song }.each |song, orders| %>           <p>(<%= orders.count %>) <%= song.title %> </p>           <p><%= song.price %> </p>         <% end %>      <% end %>    <% end %>  <% end %> 

something perhaps? (in controller)

@orders = orders.where('created_at < ? , created_at > ?', time.now.end_of_month, time.now.beginning_of_month) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -