Class: AdminResources::ResourcesController
Instance Method Summary
collapse
#admin_custom_pages, #admin_models, #admin_path_for, #after_sign_in_path_for, #after_sign_out_path_for
Instance Method Details
#create ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 22
def create
puts "[AdminResources::ResourcesController] create #{model_name}"
@resource = model_class.new(resource_params)
if @resource.save
sync_join_associations
flash[:new_url] = admin_path_for(model_name, :new)
redirect_to admin_path_for(model_name, :show, @resource), notice: "#{model_name} was successfully created."
else
render :new, status: :unprocessable_entity
end
end
|
#custom_action ⇒ Object
Dispatches to a host-app controller action via a configured custom action. The host app must define a route that this proxies to, specified as ‘handler`. If no handler is configured, falls back to calling a same-named method on the resource.
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 57
def custom_action
action_name_param = params[:custom_action]
action_config = custom_actions.find { |a| a[:name].to_s == action_name_param }
unless action_config
redirect_to admin_path_for(model_name, :show, @resource), alert: "Unknown action."
return
end
handler = action_config[:handler]
if handler
handler.call(@resource, self)
else
if @resource.respond_to?(action_name_param)
@resource.public_send(action_name_param)
redirect_to admin_path_for(model_name, :show, @resource),
notice: "#{action_config[:label] || action_name_param} completed."
else
redirect_to admin_path_for(model_name, :show, @resource), alert: "Action not implemented."
end
end
end
|
#destroy ⇒ Object
48
49
50
51
52
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 48
def destroy
puts "[AdminResources::ResourcesController] destroy #{model_name}##{@resource.id}"
@resource.destroy
redirect_to admin_path_for(model_name, :index), notice: "#{model_name} was successfully deleted."
end
|
#edit ⇒ Object
34
35
36
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 34
def edit
puts "[AdminResources::ResourcesController] edit #{model_name}##{@resource.id}"
end
|
#index ⇒ Object
8
9
10
11
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 8
def index
puts "[AdminResources::ResourcesController] index for #{model_name}"
@resources = filter_resources(model_class.all).order(id: :desc)
end
|
#new ⇒ Object
17
18
19
20
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 17
def new
puts "[AdminResources::ResourcesController] new #{model_name}"
@resource = model_class.new
end
|
#show ⇒ Object
13
14
15
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 13
def show
puts "[AdminResources::ResourcesController] show #{model_name}##{@resource.id}"
end
|
#update ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/admin_resources/resources_controller.rb', line 38
def update
puts "[AdminResources::ResourcesController] update #{model_name}##{@resource.id}"
if @resource.update(resource_params)
sync_join_associations
redirect_to admin_path_for(model_name, :show, @resource), notice: "#{model_name} was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
|