Sha256: 5480861e936a630cd9135296a6fa6bf1d7b9bd46501ddb0017f91f221380abc2
Contents?: true
Size: 700 Bytes
Versions: 1
Compression:
Stored size: 700 Bytes
Contents
module AuthHelpers # Helper that find or initialize an object by attribute only if the given value # is not blank. If it's blank, create a new object using :new. # def self.find_or_initialize_by_unless_blank(klass, attr, value) if value.blank? klass.new else klass.send(:"find_or_initialize_by_#{attr}", value) end end # Creates a new record, assigning the perishable token and an error message. # def self.new_with_perishable_token_error(klass, message=:invalid, options={}) record = klass.new(options) record.perishable_token = options[:perishable_token] record.errors.add(:perishable_token, :invalid, :default => message) record end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
josevalim-auth_helpers-0.5.1 | lib/auth_helpers.rb |