date - Ruby on Rails: How to get the current week and loop through it to display its days? -


enter image description here

the above picture mean. think code should like:

    <% @days_from_this_week.each |day| %>         <%= day.name %>         <!--e.g. monday-->         <% day.sessions |session| %>             <% @session_categories.each |category| %>                 <!--categories means sesion1/2/3/4 category                 day's sessionx empty, have determine wheather session matches cateogry,                  , display in table                 -->                 <% if session.category == category %>                     <%= session.content %>                  <% end %>             <% end %>          <% end %>     <% end %> 

but how current week? , how name of day? , navigate through calendar, pre_week , next_week needed.

i foundprev_week , next_week method, seems return day after week, not need.

a possible solution here, don't know how use it.

update: found workable solution, still looking better code:

  <!--  @date = params[:date] ? date.parse(params[:date]) : date.today     first=@date.at_beginning_of_week     last=@date.at_beginning_of_week + 6     @days= (first..last).to_a-->     <% @days.each |day| %>         <div>           <%= day %>         </div>      <% end %> 

try in controller you're setting @days_from_this_week

today = date.today # today's date @days_from_this_week = (today.at_beginning_of_week..today.at_end_of_week).map 

to show does:

> (today.at_beginning_of_week..today.at_end_of_week).map.each { |day| day } > [mon, 12 aug 2013, tue, 13 aug 2013, wed, 14 aug 2013, thu, 15 aug 2013, fri, 16 aug 2013, sat, 17 aug 2013, sun, 18 aug 2013] 

update additional request of querying articles published on:

find articles between start date's midnight next day.

start_time = time.parse(date.to_s) end_time = 1.day.since(start_time) article.where('published_on >= ? , published_on < ?', start_time, end_time) 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -