Module: ActiveAdmin::ActsAsList::DSL
- Defined in:
- lib/active_admin/acts_as_list/dsl.rb
Instance Method Summary collapse
-
#sortable_member_actions ⇒ Object
Call this inside your resource definition to add the needed member actions for your sortable resource.
Instance Method Details
#sortable_member_actions ⇒ Object
Call this inside your resource definition to add the needed member actions for your sortable resource.
Example:
#app/admin/players.rb
ActiveAdmin.register Player do
# Sort players by position
config.sort_order = 'position'
# Add member actions for positioning.
sortable_member_actions
end
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_admin/acts_as_list/dsl.rb', line 19 def sortable_member_actions member_action :move_to_top do if resource.first? redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_to_top', :resource => resource_class.to_s.camelize.constantize.model_name.human ) return end resource.move_to_top redirect_to :back, :notice => I18n.t('acts_as_list.moved_to_top', :resource => resource_class.to_s.camelize.constantize.model_name.human ) end member_action :move_to_bottom do if resource.last? redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_to_bottom', :resource => resource_class.to_s.camelize.constantize.model_name.human ) return end resource.move_to_bottom redirect_to :back, :notice => I18n.t('acts_as_list.moved_to_bottom', :resource => resource_class.to_s.camelize.constantize.model_name.human ) end member_action :move_up do if resource.first? redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_up', :resource => resource_class.to_s.camelize.constantize.model_name.human ) return end resource.move_higher redirect_to :back, :notice => I18n.t('acts_as_list.moved_up', :resource => resource_class.to_s.camelize.constantize.model_name.human ) end member_action :move_down do if resource.last? redirect_to :back, :notice => I18n.t('acts_as_list.illegal_move_down', :resource => resource_class.to_s.camelize.constantize.model_name.human ) return end resource.move_lower redirect_to :back, :notice => I18n.t('acts_as_list.moved_down', :resource => resource_class.to_s.camelize.constantize.model_name.human ) end end |