Sha256: 405561346a0626dd9a97d97dcaf02681c711a51d364390d8573f70581f01863e
Contents?: true
Size: 766 Bytes
Versions: 1
Compression:
Stored size: 766 Bytes
Contents
class Redirect < ActiveRecord::Base attr_accessible :pattern, :to validates_presence_of :pattern, :to validates_uniqueness_of :position, :allow_blank => true scope :ordered, order('position') before_create :assign_position def self.update_order(ordered_redirect_ids) success = true transaction do begin update_all :position => nil ordered_redirect_ids.each_with_index do |r_id, idx| r = find(r_id) r.position = idx r.save! end rescue # TODO log exception success = false raise ActiveRecord::Rollback end end success end private def assign_position self.position = ( self.class.maximum(:position) || -1 ) + 1 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rest-assured-0.1.0 | lib/rest-assured/models/redirect.rb |