Skip to content

Commit

Permalink
make it backwards compatible
Browse files Browse the repository at this point in the history
Signed-off-by: Ethan Vizitei <ethan.vizitei@gmail.com>
  • Loading branch information
evizitei committed Jul 13, 2011
1 parent fccfe78 commit b392315
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
17 changes: 14 additions & 3 deletions Gemfile.lock
Expand Up @@ -6,10 +6,20 @@ PATH
GEM
remote: http://rubygems.org/
specs:
activerecord (2.3.12)
activesupport (= 2.3.12)
activesupport (2.3.12)
activemodel (3.0.9)
activesupport (= 3.0.9)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.9)
activemodel (= 3.0.9)
activesupport (= 3.0.9)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activesupport (3.0.9)
arel (2.0.10)
builder (2.1.2)
diff-lcs (1.1.2)
i18n (0.5.0)
rake (0.9.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
Expand All @@ -20,6 +30,7 @@ GEM
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
sqlite3 (1.3.3)
tzinfo (0.3.29)

PLATFORMS
ruby
Expand Down
12 changes: 11 additions & 1 deletion lib/acts_as_restful_list.rb
Expand Up @@ -84,7 +84,17 @@ def reset_order_after_destroy
end

def initialize_order
self.class.where(scope_condition).select(:id).each_with_index do |item,idx|
initial_set = []

if self.class.respond_to? :where
#Rails 3.x
initial_set = self.class.where(scope_condition).select(:id).order("created_at ASC")
else
#Rails 2.x
initial_set = self.class.find(:all,:conditions=>scope_condition,:select=>"id",:order=>"created_at ASC")
end

initial_set.each_with_index do |item,idx|
ActiveRecord::Base.connection.execute("update #{self.class.table_name} set position = #{idx + 1} where id = #{item.id};")
end
end
Expand Down

0 comments on commit b392315

Please sign in to comment.