我有以下的模型驗證驗證顯示,即使被公佈值誤差
validates_presence_of :enddate
validates_presence_of :startdate
這是什麼東西被張貼
Parameters: {"utf8"=>"✓", "authenticity_token"=>"QczhHQoDU7a0/WKnUnLlzQ9Aob/NQOj1naiwfOYIW1c=",
"billsanddeposit"=>{"name"=>"Test Bill Item",
"itemcategory_id"=>"2", "repeatsevery"=>"2", "startdate"=>"01/24/2013", "enddate"=>"01/31/2013",
"deposit"=>"0", "amount"=>"100"}, "commit"=>"Create Billsanddeposit"}
而這些是被顯示出來
Enddate can't be blank
Startdate can't be blank
錯誤
這些是數據庫中的日期時間字段,當腳手架最初創建表單時,h廣告date_select。我將其更改爲帶有jQuery日期選擇器的text_field,現在即使我可以看到如上所示發佈的值,我也會得到上述錯誤,表明它們沒有被看到。
這裏的一切我已經做了迄今爲止的是添加的關係和驗證整個模型
class Billsanddeposit < ActiveRecord::Base
attr_accessible :amount, :bankaccount_id, :deposit, :enddate, :itemcategory_id, :name, :repeatsevery, :repeattype_id, :startdate
validates_presence_of :amount
validates_presence_of :bankaccount_id
validates_presence_of :itemcategory_id
validates_presence_of :enddate
validates_presence_of :name
validates_presence_of :repeatsevery
validates_presence_of :repeattype_id
validates_presence_of :startdate
belongs_to :bankaccount
belongs_to :repeattype
belongs_to :itemcategory
has_many :ledgeritems
end
。
這裏的控制器,幾乎完全默認
def create
@billsanddeposit = Billsanddeposit.new(params[:billsanddeposit])
respond_to do |format|
if @billsanddeposit.save
@billsanddeposits = Billsanddeposit.joins(:bankaccount).where("bankaccounts.user_id = ?", current_user.id)
@billsanddeposit = Billsanddeposit.new
format.html { redirect_to @billsanddeposit, :notice => 'Billsanddeposit was successfully created.' }
format.json { render :json => @billsanddeposit, :status => :created, :location => @billsanddeposit }
else
@billsanddeposits = Billsanddeposit.joins(:bankaccount).where("bankaccounts.user_id = ?", current_user.id)
format.html { render :action => "index" }
format.json { render :json => @billsanddeposit.errors, :status => :unprocessable_entity }
end
end
end
嘗試使用'DateTime.parse(日期)'分析日期' – MrYoshiji
控制器是默認的腳手架嗎? –
你有'attr_accessible'作爲':enddate'和':startdate'嗎? – hyperrjas