samedi 14 mai 2016

How to get the date only on a DateTime attribute?

Hello i am working with a Calender. and i think that calendar deals only with date without a time.

Note: requested_date is a DateTime Attribute. i want to get all reservations with requested date and covert it to date only

users_controller.rb

def myprofile
    @reservation = Reservation.all
    @resv_by_date = @reservation.group_by(&:requested_date) <-- make requested_date to date only
end

myprofile.html.erb

<div id="admin">
<%= calendar do |date| %>
    <%= date.day %>
    <%= @resv_by_date %>
    <ul>
    <% @resv_by_date[date].each do |r| %>
        <li><%= link_to r.requested_date, r %></li>
    <% end %>
    </ul>
    <%end %>
<% end %>
</div>

Here is the output image

(this month 'May') requested_date is existing on my database

Aucun commentaire:

Enregistrer un commentaire