Class: RademadeAdmin::ModelController
Instance Attribute Summary
#form_fields_with_locale, #form_fields_without_locale, #item_name, #list_fields, #model_class, #model_info, #model_name
#current_user
Instance Method Summary
collapse
configuration, item_name, model_class, model_info, model_name, options, parent_menu_item
Methods included from Notifier
#success_action, #success_delete, #success_insert, #success_link, #success_message, #success_status_change, #success_unlink, #success_update
Methods included from Templates
#abstract_template, #form_template_path, #native_template_folder
#filter_fields, #load_field_options, #load_model_options, #load_options, #load_template_options, #origin_fields
#edit_breadcrumbs, #list_breadcrumbs, #new_breadcrumbs, #related_breadcrumbs, #root_breadcrumbs
Methods included from UriHelper
#admin_autocomplete_uri, #admin_create_uri, #admin_delete_uri, #admin_edit_form_uri, #admin_edit_uri, #admin_link_autocomplete_uri, #admin_link_uri, #admin_list_uri, #admin_model_url_for, #admin_new_form_uri, #admin_new_uri, #admin_related_item, #admin_related_uri, #admin_unlink_uri, #admin_update_uri, #admin_url_for, #rademade_admin_route, #root_uri
Instance Method Details
#autocomplete ⇒ Object
45
46
47
48
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 45
def autocomplete
authorize! :read, model_class
render :json => Autocomplete::BaseSerializer.new(autocomplete_items)
end
|
#create ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 18
def create
authorize! :create, model_class
saver = RademadeAdmin::Saver.new(model_info, params)
saver.create_model
saver.save_data
success_insert saver.item
rescue Exception => e
render_record_errors e
end
|
#destroy ⇒ Object
38
39
40
41
42
43
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 38
def destroy
@item = model.find(params[:id])
authorize! :destroy, @item
@item.delete if @item
success_delete @item
end
|
#edit ⇒ Object
75
76
77
78
79
80
81
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 75
def edit
@item = model.find(params[:id])
authorize! :update, @item
@with_create_and_return_button = true
edit_breadcrumbs
render_template
end
|
122
123
124
125
126
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 122
def form
authorize! :read, model_class
@item = params[:id].blank? ? new_model : model.find(params[:id])
render form_template_path(true), :layout => false
end
|
#index ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 57
def index
authorize! :read, model_class
list_breadcrumbs
@items = index_items
respond_to do |format|
format.html { render_template }
format.json { render :json => @items }
end
end
|
#link_autocomplete ⇒ Object
50
51
52
53
54
55
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 50
def link_autocomplete
authorize! :read, model_class
relation_service = RademadeAdmin::RelationService.new
@related_model_info = relation_service.related_model_info(model_info, params[:relation])
render :json => Autocomplete::LinkSerializer.new(link_autocomplete_items, model.find(params[:id]), params[:relation])
end
|
#new ⇒ Object
67
68
69
70
71
72
73
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 67
def new
authorize! :create, model_class
@with_create_and_return_button = true
@item = new_model
new_breadcrumbs
render_template
end
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 83
def related
authorize! :read, model_class
@related_model_info = RademadeAdmin::RelationService.new.related_model_info(model_info, params[:relation])
@item = model.find(params[:id])
search_params = params.except(:id)
@items = related_items(search_params)
@sortable_service = RademadeAdmin::SortableService.new(@related_model_info, search_params)
respond_to do |format|
format.html {
related_breadcrumbs
render_template
}
format.json { render :json => Autocomplete::BaseSerializer.new(@items) }
end
end
|
99
100
101
102
103
104
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 99
def related_add
@item = model.find(params[:id])
linker = Linker.new(model_info, @item, params[:relation])
linker.link(params[:related_id])
success_link
end
|
106
107
108
109
110
111
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 106
def related_destroy
@item = model.find(params[:id])
linker = Linker.new(model_info, @item, params[:relation])
linker.unlink(params[:related_id])
success_unlink
end
|
#show ⇒ Object
113
114
115
116
117
118
119
120
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 113
def show
@item = model.find(params[:id])
authorize! :read, @item
respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :json => @item }
end
end
|
#sort ⇒ Object
128
129
130
131
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 128
def sort
sortable_service.sort_items
success_action
end
|
#update ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/rademade_admin/model_controller.rb', line 28
def update
saver = RademadeAdmin::Saver.new(model_info, params)
saver.find_model
authorize! :update, saver.item
saver.save_data
success_update saver.item
rescue Exception => e
render_record_errors e
end
|