Skip to content

Instantly share code, notes, and snippets.

@dmz006
Created December 3, 2013 22:08
Show Gist options
  • Save dmz006/7778415 to your computer and use it in GitHub Desktop.
Save dmz006/7778415 to your computer and use it in GitHub Desktop.
Custom validation method issues
class Item < ActiveRecord::Base
attr_accessible :description
validate :description_check, :on => create, :if => details?
validate :description_check, :on => update
private
def details?
current_step == "details"
end
def description_check
description_test = description.gsub(/[[:space:]\:\w\(\)\-\%\!\_\.\,\"\'\&\/\#\$]+/, "")
errors.add(:base, description_test) unless description_test.nil? || description.test.empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment