0

Well, I want to display departure and arrival times(with dates) for my flights application.

I had created two fields 'departure' and 'arrival' with data-type datetime.

What methods can be used for these in the controller aand how can i show them in the index page.

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
Pavan
  • 33,316
  • 7
  • 50
  • 76

2 Answers2

1

Something like:

<%= flight.arrival.strftime('%Y-%m-%d %H:%M') %>

Or better place a method for formatting in the model.

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
  • 1
    I used the below for selecting date: <%= date_select(:flight,:departure, {:order => [:day, :month, :year],:prompt => { :day => '-', :month => '-', :year => '-' } }, {:style => "width: 80px"}) %> Is der any of the same like selecting time. – Pavan May 17 '13 at 06:38
0

suppose you have a arrival & departure in your flights table then

In controller

@flights = Flight.all

In view

<% for flight in @flights%>
  <%= flight.arrival %>
  <%= flight.departure %>
<% end %>
Salil
  • 46,566
  • 21
  • 122
  • 156