Module: MetaController::Adaptors::DestroyManyAction

Defined in:
lib/meta_controller/adaptors/destroy_many_action.rb

Instance Method Summary collapse

Instance Method Details

#destroy_many_actionObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/meta_controller/adaptors/destroy_many_action.rb', line 6

def destroy_many_action
  controller_eval do
    define_callbacks :before_destroy_many_find
    define_callbacks :after_destroy_many_find
  end
  define_controller_method(:destroy_many, %{
    run_callbacks(:before_destroy_many_find)
    selected_ids = params[:#{short_model_name.pluralize}].collect { |id, state| state.to_i == 1 ? id.to_i : nil }
    selected_ids.compact!
    selected_records = #{model_name}.all(:conditions => { :id => selected_ids })
    run_callbacks(:after_destroy_many_find)
    
    selected_records.each { |r| r.destroy }
    
    redirect_to #{long_model_name.pluralize}_path
  })
end