<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: positive code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 07:38:12 GMT</pubDate>
    <description>DZone Snippets: positive code</description>
    <item>
      <title>Defining a custom validates in rails</title>
      <link>http://snippets.dzone.com/posts/show/822</link>
      <description>in the model:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class User &lt; ActiveRecord::Base&lt;br /&gt;  require 'validations'&lt;br /&gt;&lt;br /&gt;  validates_positive_or_zero :number&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;in /lib/validations.rb:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def validates_positive_or_zero(*attr_names)&lt;br /&gt;  configuration = { :message =&gt; "Cannot be negative" }&lt;br /&gt;  configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)&lt;br /&gt;  validates_each attr_names do |m, a, v| m.errors.add(a, configuration[:message]) if v&lt;0 end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 19 Oct 2005 21:47:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/822</guid>
      <author>zzzrByte (Tal Ater)</author>
    </item>
  </channel>
</rss>
