How to put this datetime in a new form?

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?

Try:

<%= f.date_select(:sales_date, :discard_day => 1) %>

Eric

Thnaks, it works! Now I obtain Year - Month. O would like to obtain
Month - Year. Is it possible?

You specify an additional option of :order

<%= f.date_select :sales_date, :discard_day => true, :order => [:month, :year] %>

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.

.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.

# environment.rb

Time::DATE_FORMATS[:special] = "%m-%Y"

# /app/views/any_view.html.erb

<td><%=h @ticket.sales_date.to_s(:special)%> </td>