Skip to content

Commit

Permalink
Adding a nil option to :add_new_at to allow new items to start off th…
Browse files Browse the repository at this point in the history
…e list
  • Loading branch information
forrest committed Feb 22, 2013
1 parent 9dc4d51 commit 923484e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/acts_as_list/active_record/acts/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module ClassMethods
# * +top_of_list+ - defines the integer used for the top of the list. Defaults to 1. Use 0 to make the collection
# act more like an array in its indexing.
# * +add_new_at+ - specifies whether objects get added to the :top or :bottom of the list. (default: +bottom+)
# `nil` will result in new items not being added to the list on create
def acts_as_list(options = {})
configuration = { :column => "position", :scope => "1 = 1", :top_of_list => 1, :add_new_at => :bottom}
configuration.update(options) if options.is_a?(Hash)
Expand Down Expand Up @@ -92,10 +93,14 @@ def add_new_at
before_destroy :reload_position
after_destroy :decrement_positions_on_lower_items
before_create :add_to_list_#{configuration[:add_new_at]}
after_update :update_positions
before_update :check_scope
EOV

if configuration[:add_new_at].present?
self.send(:before_create, "add_to_list_#{configuration[:add_new_at]}")
end

end
end

Expand Down

0 comments on commit 923484e

Please sign in to comment.