Class: Admin::BaseController
Constant Summary
Redde::IndexHelper::IGNORED_COLUMNS
Instance Method Summary
collapse
#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
#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
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
24
25
26
|
# File 'app/controllers/admin/base_controller.rb', line 24
def edit
instance_variable_set("@#{record}", model_name.find(params[:id]))
end
|
#index ⇒ Object
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
|
#new ⇒ Object
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
|
#sort ⇒ Object
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
|
#update ⇒ Object
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
|