Skip to content

@tute /sortable_controller_methods.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rails SortableMethods
# lib/sortable_controller_methods.rb (must then load lib files manually)
# Add in "sortable" controllers:
# include SortableControllerMethods
#
# As in http://railscasts.com/episodes/147-sortable-lists
module SortableControllerMethods
def sort
klass.all.each do |object|
object.position = params[object.class.to_s.downcase].index(object.id.to_s) + 1
object.save
end
render :nothing => true
end
# May be common index action (or where sort options are displayed)
def order
instance_variable_set("@" + controller_name, klass.all)
end
def klass
controller_name.singularize.camelize.constantize
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.