I feel I should qualify all of my questions by saying I am brand new to Rails 3, so forgive me my newbiness. I've been reading the ActionView Date Helpers, but cannot figure out how to complete this simple function. In Rails 3, I want to spit out an html list with the last 10 days. So, for instance, it would look like this today:
<li>Tuesday, February 8</li>
<li>Monday, February 7</li>
<li>Sunday, February 6</li>
<li>Saturday, February 5</li>
<li>Friday, February 4</li>
<li>Thursday, February 3</li>
<li>Wednesday, February 2</li>
<li>Tuesday, Feb开发者_如何学Cruary 1</li>
<li>Monday, January 31</li>
<li>Sunday, January 30</li>
It seems like it would be simple, but I cannot figure it out. Anyone care to give it a shot?
<%- Date.today.downto(Date.today - 9.days) do |date| %>
<li><%= date %></li>
<%- end %>
You may want to try looking into strftime to allow you to format information about dates. A website with some ruby strftime formatting can be fount at http://www.foragoodstrftime.com/
This should do it:
<% 10.downto(1).each do |day| %>
<li><%= day.days.ago.strftime("%A, %B %d") %></li>
<% end %>
How about:
<%= (0..10).map { |i| "<li>#{i.days.ago.strftime('%A, %B %d')}</li>" }.join %>
精彩评论