我在軌道上比較紅寶石日期時陷入了奇怪的問題。在軌道上比較紅寶石日期
這是我想要做的。我已經解析了一個文件並選擇了一個日期到一個變量@timeinFile
。我正在將此值與我的User
的created_at
進行比較。這裏是代碼:
@date=User.last.created_at
@arr.each do |i|
j=i.partition('(')[2]
@timeinFile=j.partition(')')[0].to_datetime
if @date < @timeinFile #Error: undefined method `to_datetime' for nil:NilClass
@val='true'
end
end
if語句和粘貼值分別我得到下面的輸出
<p> <%= @date %> </p> ----------> 2013-08-05 09:16:33 UTC
<p><%= @timeinFile.to_time %></p> -------------> 2012-10-02 12:00:00 UTC
PLZ有人告訴我,我做了什麼錯了,當我的評論。
編輯
<a href="http://www.cpsc.gov/en/Recalls/2013/Fitness-Anywhere-Recalls-Early-Model-Suspension-Trainer-Devices-Due-to-Fall-Hazard/" target="_blank">Fitness Anywhere Recalls Early Model Suspension Trainer Devices Due to Fall Hazard</a> (Tue, 02 Oct 2012 12:00:00 GMT) Fitness Anywhere has received 570 reports of the strap length adjustment buckles breaking with 13 reports of injuries. TRX suspension trainers sold from 2006 through 2009. </p> </body> </html>
這是我在@arr讓行。下一步是與(
,然後用)
分區得到圓括號日期...
您確定錯誤指向比較嗎? –
當出現錯誤時,查看「@ arr」的內容會很有用。 –
@MarekLipka是的,它指向同一行:( –