Class: Admin::BaseController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Redde::AdminHelper, Redde::IndexHelper
Defined in:
app/controllers/admin/base_controller.rb

Direct Known Subclasses

ManagersController, SystemCommandsController

Constant Summary

Constants included from Redde::IndexHelper

Redde::IndexHelper::IGNORED_COLUMNS

Instance Method Summary collapse

Methods included from Redde::IndexHelper

#ancestry_options, #ancestry_tree, #collection, #column_names, #excluded_column_names, #form_column_names, #index_columns, #index_value_for, #list_table, #list_table_options, #model_name, #record, #render_item_column, #show_tree, #sort_priority, #sort_table_options, #title_for, #title_symbol_for

Methods included from Redde::AdminHelper

#command_link, #page_header, #page_sidebar, #redde_file_field_tag, #redde_flash, #redde_page, #redde_tree, #redde_tree_list, #sidebar_link, #taccusative, #tplural, #tsingular

Instance Method Details

#createObject



19
20
21
22
# File 'app/controllers/admin/base_controller.rb', line 19

def create
  instance_variable_set("@#{record}", model_name.new(params[record.to_sym].permit!))
  redirect_or_edit(instance_variable_get("@#{record}"), instance_variable_get("@#{record}").save)
end

#destroyObject



33
34
35
36
37
# File 'app/controllers/admin/base_controller.rb', line 33

def destroy
  instance_variable_set("@#{record}", model_name.find(params[:id]))
  instance_variable_get("@#{record}").destroy
  redirect_to send("admin_#{collection}_path"), notice: "#{model_name.model_name.human} удалена."
end

#editObject



24
25
26
# File 'app/controllers/admin/base_controller.rb', line 24

def edit
  instance_variable_set("@#{record}", model_name.find(params[:id]))
end

#indexObject



9
10
11
12
# File 'app/controllers/admin/base_controller.rb', line 9

def index
  instance_variable_set("@#{collection}", scope)
  return render 'tree' if column_names.include?('ancestry')
end

#newObject



14
15
16
17
# File 'app/controllers/admin/base_controller.rb', line 14

def new
  instance_variable_set("@#{record}", model_name.new)
  render 'edit'
end

#sortObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/admin/base_controller.rb', line 39

def sort
  if column_names.include?('ancestry')
    model_name.sort(params[:list])
  else
    params[:pos].each_with_index do |id, idx|
      p = model_name.find(id)
      p.update(position: idx)
    end
  end
  render nothing: true
end

#updateObject



28
29
30
31
# File 'app/controllers/admin/base_controller.rb', line 28

def update
  instance_variable_set("@#{record}", model_name.find(params[:id]))
  redirect_or_edit(instance_variable_get("@#{record}"), instance_variable_get("@#{record}").update(params[record.to_sym].permit!))
end