how to convert a hash value returned from a date_select in rails to a Date object?

前端 未结 5 1663
感动是毒
感动是毒 2020-12-18 00:50

I have a date_select in my view inside a form, however on submit the value returned is in a hash form like so:

{\"(1i)\"=>\"2010\", \"(2i)\"=>\"8\", \"         


        
5条回答
  •  离开以前
    2020-12-18 01:13

    Date.new(*params["due_date"].values.map(&:to_i))
    

    Note: Works in ruby 1.9.2+ since it depends on the order of the hash elements.

    Two goodies here:

    • Symbol to Proc
    • Splat operator

提交回复
热议问题