在nil,datetime字段中显示字符串

时间:2015-02-13 20:43:20

标签: ruby-on-rails postgresql datetime

如果datetime字段的值为nil

,我正在尝试更改单元格的值

但它会不断将值更改为今日日期

            -elsif k=='pickup' || k=='delivery' || k=='Posted On'
              - if v.nil?
                = "Unknown"
              - else
                = v.strftime("%D")


Load.find(load_id).delivery.nil? 
=> true
Load.find(load_id)
=> #<Load id: 904237, length: 53, delivery: nil, pickup: "2014-09-09 17:00:00", weight: nil, equipment_id: 26, covered: false, created_at: "2014-08-18 13:21:25", updated_at: "2014-11-24 21:55:03"> 

实际上我已经进一步缩小范围猜猜它不在我看来......

但实际上当我从我的控制器中的数据库中提取它时...它将@load设置为默认传递值

显示控制器:

   def show
    if params[:load]
      params[:load].delete(:type)
      params[:load][:origin] = Location.to_point(params[:load][:origin])
      params[:load][:dest] = Location.to_point(params[:load][:dest])
      @load = Load.new(params[:load])
      @load.updated_at = Time.now
      flash.keep[:notice] = 'Please be aware that it could take up to 5 minutes for your load to appear in search results.'
    else
      @load = Load.find(params[:id])
      current_location(@load)
      @return_hotloads = Hotload.return_hotloads(@load)
      @return_loads = Load.return_loads(@load)
    end
    authorize! :show, @load
  end

交货应该是零

@load 
=>      
#<Load id: 904237, user_id: 10640, delivery: "2015-02-13 21:48:21", pickup: "2014-09-09 17:00:00", weight: nil, tracking: nil>

但如果我在视图中执行此操作,它会显示为我想要的空白:

            -elsif k=='delivery'
              - l = Load.find(@load.id).delivery
              - if l
                = l.strftime("%D")
女巫真的很奇怪....

enter image description here

0 个答案:

没有答案