ruby-on-rails – 导致此无效日期错误的原因是什么?
发布时间:2020-12-17 03:58:31 所属栏目:百科 来源:网络整理
导读:在这行代码上: @note.date = Date.strptime(params[:custom_date],'%d-%m-%Y') unless params[:custom_date].blank? 我收到此错误: ArgumentError: invalid date/usr/ruby1.9.2/lib/ruby/1.9.1/date.rb:1022 以下是参数: { "commit" = "Create","utf8" =
在这行代码上:
@note.date = Date.strptime(params[:custom_date],'%d-%m-%Y') unless params[:custom_date].blank? 我收到此错误: ArgumentError: invalid date /usr/ruby1.9.2/lib/ruby/1.9.1/date.rb:1022 以下是参数: { "commit" => "Create","utf8" => "342234223","authenticity_token" => "RKYZNmRaElg/hT5tlmLcqnstnOapdhiaWmDcjNDtSOI=","action" => "create","note" => { "name"=>"note1","detail"=>"detail" },"controller" => "notes","custom_date" => "03-03-2010" } 导致此错误的原因是什么?谢谢阅读. 解决方法
你得到的参数是
{"commit"=>"Create","utf8"=>"342234223","authenticity_token"=>"RKYZNmRaElg/hT5tlmLcqnstnOapdhiaWmDcjNDtSOI=","action"=>"create","note"=> {"name"=>"note1","detail"=>"detail"},"controller"=>"notes","custom_date"=>"03-03-2010"} 因此我们可以清楚地表明 它不是参数[:custom_date]但它是params [‘custom_date’] UPDATE Date.strptime方法遵循特定模式.例如 str = "01-12-2010" #DD-MM-YYYY then use Date.strptime(str,"%d-%m-%Y") 但如果 str = "2010-12-01" #YYYY-MM-DD then use Date.strptime(str,"%Y-%m-%d") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |