[英]Rollback transaction with validations turned off in ActiveRecord
模型:
class Project < ActiveRecord::Base
attr_accessible :description, :due_date, :expiration_date, :extra_reward, :hours_needed, :location, :mission, :participants_id, :project_picture, :required_skill, :title, :gnikles, :topic, :community_id
belongs_to :user
belongs_to :community
has_many :skills
validates :title, :presence => true, :length => { :maximum => 100 }
validates :hours_needed, :presence => true, :inclusion => { :in => 0..20 }, :numericality => true
validates :description, :presence => true
validates :required_skill, :presence => true
validates :due_date, :presence => true
#validates :expiration_date, :presence => true
end
嘗試創建一個測試項目,我得到以下信息:
1.9.3-p194 :025 > Project.create(:title =>"Testings", :description =>"fdsafdsfsa", :topic => 33, :community_id => 3, :expiration_date => "09/09/2013", :due_date =>"09/28/2013", :hours_needed => 1, :required_skill =>1)
(0.1ms) begin transaction
(0.0ms) rollback transaction
=> #<Project id: nil, title: "Testings", description: "fdsafdsfsa", required_skill: 1, extra_reward: nil, expiration_date: "2013-09-09 00:00:00", due_date: nil, hours_needed: 1, views: nil, user_id: nil, topic: 33, gnikels: 0, completed: 0, created_at: nil, updated_at: nil, community_id: 3>
為什么Due_date不會傳遞,但是expiration_date出現沒有問題?
由於"09/28/2013"
不是有效的日期字符串,因此:
'09/28/2013'.to_date # => ArgumentError: invalid date
'28/09/2013'.to_date # => Sat, 28 Sep 2013
'2013-09-28'.to_date # => Sat, 28 Sep 2013
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.