Rails Format Date in Drop Down List in View

后端 未结 2 669
臣服心动
臣服心动 2021-01-14 22:56

I could you some assistance formatting a date field in a drop-down list in a for in a view. My dates are showing with a time-stamp and I\'d like them to show as \"mm/dd/yyy

2条回答
  •  抹茶落季
    2021-01-14 23:33

    In your model add the following method

      def event_date_formatted
        event_date.strftime("%m/%d/%Y")
      end
    

    Then you can simply use like so:

    <%= select_tag "event_date", options_from_collection_for_select(UgradRsvp.get_event_dates, 'event_date', :event_date_formatted) %>
    

提交回复
热议问题