How to get a Date from date_select or select_date in Rails?

后端 未结 7 1325
小鲜肉
小鲜肉 2020-11-30 04:05

Using select_date gives me back a params[:my_date] with year, month and day attributes. How do get a Date ob

7条回答
  •  忘掉有多难
    2020-11-30 04:31

    With the date_select example @joofsh's answer, here's a "one liner" I use, presuming the date field is called start_date:

    ev_params = params[:event]
    
    date = Time.zone.local(*ev_params.select {|k,v| k.to_s.index('start_date(') == 0 }.sort.map {|p| p[1].to_i})
    

提交回复
热议问题