On Jan 8, 2:59 pm, Alpha Blue <li...@ruby-forum.com> wrote: > What I want to do is ensure that if the redirect box is checked for > true, that the name field matches the controller_name field precisely. > > I'm not sure if validates_presence_of will do it. I may have to create > a custom validation but am unsure how to proceed. > validates_presence_of doesn't do that.
Custom validations aren't scary. Adding a class method like def validates_foo(*attr_names) options = attr_names.extract_options! validates_each(attr_names, options) do |record, attr_name, value| record.errors.add(attr_name, options[:message]) if ... end end end lets you do validates_foo :attr1, :attr2 You get stuff like :if and :unless for free Fred
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.