Module: E9Rails::Controllers::Sortable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/e9_rails/controllers/sortable.rb
Overview
Module to give a controller “sortable” functionality.
To implement this there must exist a POST route to the collection url named update_order which passes an array, “ids”, representing the new order, e.g.
resources :sortable_things do
collection { post :update_order }
end
Instance Method Summary collapse
- #update_order(options = {}, &block) ⇒ Object (also: #update_order!)
Instance Method Details
#update_order(options = {}, &block) ⇒ Object Also known as: update_order!
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/e9_rails/controllers/sortable.rb', line 31 def update_order( = {}, &block) if params[:ids].is_a?(Array) pos = 0 params[:ids].each {|id| pos += 1; _do_position_update(id, sortable_column => pos) } flash[:notice] = I18n.t(:notice, :scope => :"flash.actions.update_order") else flash[:alert] = I18n.t(:alert, :scope => :"flash.actions.update_order") end block ||= proc {|format| format.js { head :ok } } respond_with(collection, &block) end |