Module: Controllers::Sortable
- Extended by:
- ActiveSupport::Concern
- Included in:
- ContactPointsController, Crm::ActivityAgendasController, Crm::AssortmentInstructionsController, Crm::SurveysController, CustomerFiltersController, TopicCategoriesController, TopicExamsController, TopicsController
- Defined in:
- app/concerns/controllers/sortable.rb
Overview
ActiveSupport::Concern mixin: sortable.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#perform_sort(record_class) ⇒ void
Updates each record's position to its index in the submitted id list.
-
#sort ⇒ void
Sorts records of the current controller's model by submitted position order.
Instance Method Details
#perform_sort(record_class) ⇒ void
This method returns an undefined value.
Updates each record's position to its index in the submitted id list.
21 22 23 24 25 26 27 |
# File 'app/concerns/controllers/sortable.rb', line 21 def perform_sort(record_class) param_name = record_class.name.tableize.singularize params[param_name].each_with_index do |id, index| record_class.where(id: id).update_all(position: index + 1) end head :ok end |
#sort ⇒ void
This method returns an undefined value.
Sorts records of the current controller's model by submitted position order.
14 15 16 |
# File 'app/concerns/controllers/sortable.rb', line 14 def sort perform_sort controller_name.classify.constantize end |