Rails Format Date in Drop Down List in View

后端 未结 2 670
臣服心动
臣服心动 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:48

    I not try yet, but you can try to add method to Model like

    class UgradRsvp < ActiveRecord::Base
        def event_date_text
            event_date.strftime("%d/%m/%Y")
        end
    end
    

    and then call event_date_text as txt_method

    <%= select_tag "event_date", options_from_collection_for_select(UgradRsvp.get_event_dates, "event_date", "event_date_text") %>
    

提交回复
热议问题