11175
(-- --)
March 29, 2008, 6:51pm
1
I have this is my new form:
<table>
<tr>
<th><%= _('Sales date') %></th>
</tr>
<tr>
<td> <%= f.datetime_select :sales_date %></td>
</tr>
</table>
With this code I'm showing year, month, day and hour. I only want to
show year and month. How can I do that?
11175
(-- --)
March 29, 2008, 10:01pm
2
Try:
<%= f.date_select(:sales_date, :discard_day => 1) %>
Eric
11175
(-- --)
March 30, 2008, 9:54am
3
Thnaks, it works! Now I obtain Year - Month. O would like to obtain
Month - Year. Is it possible?
radar
(Ryan Bigg)
March 30, 2008, 10:09am
4
You specify an additional option of :order
<%= f.date_select :sales_date, :discard_day => true, :order => [:month, :year] %>
11175
(-- --)
March 30, 2008, 10:34am
5
Ryan Bigg wrote:
Day month and year you mean?
@ticket.sales_date.strftime ("%m-%Y")
Thanks. I mean some kind of method, like :short. I need that because I'm
using Gettext with datetime objects.
radar
(Ryan Bigg)
March 30, 2008, 10:46am
6
.strftime is a method. You meant an argument. You’d have to change the way that ActiveSupport deals out the date formats for that. I don’t have the code on hand, sorry.
Look up the API for the datetime_select helper.
http://api.rubyonrails.org/
Julian.
11175
(-- --)
March 31, 2008, 9:08am
8
# environment.rb
Time::DATE_FORMATS[:special] = "%m-%Y"
# /app/views/any_view.html.erb
<td><%=h @ticket.sales_date.to_s (:special)%> </td>