Wow, Bingo! Genau _das_ habe ich gesucht.

Besten Dank,

Michael Kastner

Am 15.02.2011 um 14:12 schrieb Jens Krämer:

> Hallo,
> 
> On 15.02.2011, at 12:59, rubyonrails...@galt.de wrote:
> [..]
>> 
>> Mir ist bisher nichts besseres eingefallen als eine Kombination aus einem 
>> virtuellen attribut als Schalter (der im jeweiligen Controller „angeknipst“ 
>> wird) und der if-Bedingung in der Validierung:
>> 
>> class CustomerUser < ActiveRecord::Base
>> 
>> validates :telephone, :presence => true, :if => lambda{ |u| 
>> u.validate_for_user? }
> 
> 
> etwas schöner sieht es ohne das lambda aus:
> 
> validates :telephone, :presence => true, :if => :validate_for_user?
> 
> Falls du mehrere solcher Validations hast, die alle von derselben Bedingung 
> abhängen, ist with_options dein Freund [1]
> 
> 
> Grüße,
> Jens
> 
> 
> [1] http://geek.littleredstring.com/18-validations-with_options
> 
> 
> --
> Jens Krämer
> Finkenlust 14, 06449 Aschersleben, Germany
> VAT Id DE251962952
> http://www.jkraemer.net/
> 
> 
> _______________________________________________
> rubyonrails-ug mailing list
> rubyonrails-ug@headflash.com
> http://mailman.headflash.com/listinfo/rubyonrails-ug
> 

_______________________________________________
rubyonrails-ug mailing list
rubyonrails-ug@headflash.com
http://mailman.headflash.com/listinfo/rubyonrails-ug

Antwort per Email an