2013-08-27 142 views
0

有兩個型號,與客戶端驗證自定義驗證

class Quote < ActiveRecord::Base 
    attr_accessible :quote_date 
    validates :quote_date, :presence => true 
end 

class Invoice < ActiveRecord::Base 
    attr_accessible :invoice_date 
    validates :invoice_date, :presence => true 


    validate :invoice_date_lesser 

    belongs_to :quote 

    private 
    def invoice_date_lesser 
    if invoive_date < quote_date 
     errors.add(:invoice_date, 'invoice date invalid') 
    end 
    end 
end 

會有很大的幫助,如果我能得到一些解決方案,如何做到這一點的驗證 和自定義的驗證與客戶端驗證

+0

你是什麼意思給予Rails代碼客戶端驗證?使用'jquery'你可以驗證 –

+0

他意味着使用[gem客戶端驗證](https://github.com/bcardarella/client_side_validations/tree/4-0-beta) –

+0

使用client_side_validations -sorry類型錯誤 – diva

回答

0

我希望我能理解你的問題。

  1. 你想知道如何獲得,使用一個嵌套的資源

  2. 你想知道如何使驗證通過客戶端驗證

爲了驗證驗證:將參考添加到關聯的模型中

def invoice_date_lesser 
if invoive_date < quote.quote_date 
    errors.add(:invoice_date, 'invoice date invalid') 
end 

結束

對於客戶端驗證:驗證添加=>在您的form_for真正

form_for @model, :validate => true do |f| 
相關問題