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

后端 未结 7 1293
小鲜肉
小鲜肉 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:32

    Here is another one:

    # view
    <%= date_select('event', 'date') %>
    
    # controller
    date = Date.civil(*params[:event].sort.map(&:last).map(&:to_i))
    

    Found at http://kevinlochner.com/use-rails-dateselect-without-an-activerecord

提交回复
热议问题