我的模型有一个 datetime 属性(Postgres),我正在尝试通过我的 Rails 应用程序中的表单提交来创建新记录。
我提交的表单包含该日期时间属性的 text_field。它以以下格式提交日期时间作为参数:
"expires"=>"07/17/2013 12:35:26 PM"
但是,一旦它进入我的模型的 Create 操作中的第一行代码......
def create
@special_deal = SpecialDeal.new(params[:special_deal])
...大多数时候,@special_deal.expires 将 = nil
。只有很少,它工作。
我无法弄清楚为什么会这样。我猜这与在日期时间值中包含 AM 或 PM 有关,但我不确定。
参数每次都包含 expires 值:
@_params
{"utf8"=>"✓", "authenticity_token"=>"cl1SwnHOum8d/kiGnwkDsamG5IMbmdnoeFvlY11KpKc=", "special_deal"=>{"title"=>"", "provider"=>"", "description"=>"", "deal_price"=>"", "conditions"=>"", "expires"=>"07/27/2013 14:23:59", "excerpt"=>"", "original_price"=>"", "phone_number"=>"", "street"=>"", "city"=>"", "postal_code"=>"", "state"=>"", "country"=>""}, "commit"=>"Create Special deal", "action"=>"create", "controller"=>"special_deals"}
但@special_deal 没有:
@special_deal
#<SpecialDeal id: nil, man_servant_id: nil, category: "", title: "", excerpt: "", description: "", original_price: nil, deal_price: nil, provider: "", product_link: "", conditions: "", phone_number: "", street: "", city: "", postal_code: "", state: "", country: "", public: true, created_at: nil, updated_at: nil, expires: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil>