Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iirving/550305 to your computer and use it in GitHub Desktop.
Save iirving/550305 to your computer and use it in GitHub Desktop.
as per Initialize max value in Ruby on Rails ActiveRecord, automagically
def after_initialize
if self.new_record? then
if $item_sequence_order_max_value.nil? ||
( (!$item_display_order_max_dateTime.nil? )&& ( ( (Time.now - $item_display_order_max_dateTime).to_i ) > ( 10 *60 ) )) then
$item_display_order_max_value = self.class.maximum('display_order')
$item_display_order_max_value = 0 if $page_display_order_max_value.nil?
end
$item_display_order_max_dateTime = Time.now
$item_display_order_max_value += 1
self.display_order = $item_display_order_max_value
end
end
@iirving
Copy link
Author

iirving commented Aug 25, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment