I''m trying to make my validation conditional using the :if construct. If I want to just test for the existence of the field EMAIL, it seems like I could just do: :if => ''! EMAIL.nil?'' or do I have to use a proc? And if I use a proc - what gets passed into the block - I assume the currently validating field - is that right? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
On 7/19/06, Wes Gamble <weyus@att.net> wrote:> > I''m trying to make my validation conditional using the :if construct. > > If I want to just test for the existence of the field EMAIL, it seems > like I could just do: > > :if => ''! EMAIL.nil?'' > > or do I have to use a proc? > > And if I use a proc - what gets passed into the block - I assume the > currently validating field - is that right? > > Thanks, > Wes > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsHi Wes YOu need to use either a proc or a method in the :if I believe the obejct passed to the proc is the instance of the model itself. Something like :if => Proc.new { |model| model.EMAIL.nil? } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060718/671bf899/attachment.html
Wes Gamble wrote:> I''m trying to make my validation conditional using the :if construct. > > If I want to just test for the existence of the field EMAIL, it seems > like I could just do: > > :if => ''! EMAIL.nil?'' > > or do I have to use a proc? > > And if I use a proc - what gets passed into the block - I assume the > currently validating field - is that right? > > Thanks, > WesGot it working using :if => Proc.new { |job| (job.EMAIL != '''') } to only validate when this field was submitted. Of course, another trip to the source code. It was unclear from the example whether the field itself or the AR object was passed into the Proc block. Also, I couldn''t get the string form to work - I believe because I don''t understand how to pass a binding in. Wes -- Posted via http://www.ruby-forum.com/.
Possibly Parallel Threads
- text_field doesn''t call overridden ActiveRecord getters
- Wrap error_messages_for() call when no instance var present
- Best way to organize non-controller logic???
- rake migrate VERSION=0 doesn''t appear to execute
- Ajax.Request w/standard redirect doesn''t render