Skip to content

Commit

Permalink
Merge pull request #59 from miks/master
Browse files Browse the repository at this point in the history
More reliable lower/higher item detection
  • Loading branch information
swanandp committed Dec 4, 2012
2 parents 094b39c + 33d943d commit e74ea1a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/acts_as_list/active_record/acts/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,17 @@ def last?
def higher_item
return nil unless in_list?
acts_as_list_class.unscoped.find(:first, :conditions =>
"#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}"
"#{scope_condition} AND #{position_column} < #{(send(position_column).to_i).to_s}",
:order => "#{acts_as_list_class.table_name}.#{position_column} DESC"
)
end

# Return the next lower item in the list.
def lower_item
return nil unless in_list?
acts_as_list_class.unscoped.find(:first, :conditions =>
"#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}"
"#{scope_condition} AND #{position_column} > #{(send(position_column).to_i).to_s}",
:order => "#{acts_as_list_class.table_name}.#{position_column} ASC"
)
end

Expand Down

0 comments on commit e74ea1a

Please sign in to comment.