Class: Alchemy::Admin::ResourcesController
Constant Summary
Alchemy::Admin::ResourceFilter::COMMON_SEARCH_FILTER_EXCLUDES
Instance Method Summary
collapse
controller_path_array, resource_array, resource_model_name, resource_name, resources_name
#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #resource_attribute_field_options, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_instance_variable, #resources_path
#leave
Methods included from Modules
included, #module_definition_for, register_module
#current_ability
#configuration, #multi_language?, #multi_site?, #prefix_locale?
Instance Method Details
#create ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 50
def create
instance_variable_set(:"@#{resource_name}", resource_handler.model.new(resource_params))
resource_instance_variable.save
render_errors_or_redirect(
resource_instance_variable,
resources_path(resource_instance_variable.class, search_filter_params),
flash_notice_for_resource_action
)
end
|
#destroy ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 69
def destroy
resource_instance_variable.destroy
if resource_instance_variable.errors.any?
flash[:error] = resource_instance_variable.errors.full_messages.join(", ")
end
flash_notice_for_resource_action
do_redirect_to resource_url_proxy.url_for(search_filter_params.merge(action: "index", only_path: true))
end
|
#edit ⇒ Object
47
48
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 47
def edit
end
|
#index ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 20
def index
@query = resource_handler.model.ransack(search_filter_params[:q])
@query.sorts = default_sort_order if @query.sorts.empty?
items = @query.result
items = items.includes(*resource_relations_names) if contains_relations?
items = items.tagged_with(search_filter_params[:tagged_with]) if search_filter_params[:tagged_with].present?
respond_to do |format|
format.html do
items = items.page(params[:page] || 1).per(items_per_page)
instance_variable_set(:"@#{resources_name}", items)
end
format.csv do
instance_variable_set(:"@#{resources_name}", items)
end
end
end
|
#new ⇒ Object
39
40
41
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 39
def new
instance_variable_set(:"@#{resource_name}", resource_handler.model.new)
end
|
#resource_handler ⇒ Object
78
79
80
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 78
def resource_handler
@_resource_handler ||= Alchemy::Resource.new(controller_path, alchemy_module)
end
|
#show ⇒ Object
43
44
45
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 43
def show
render action: "edit"
end
|
#update ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 60
def update
resource_instance_variable.update(resource_params)
render_errors_or_redirect(
resource_instance_variable,
resources_path(resource_instance_variable.class, search_filter_params),
flash_notice_for_resource_action
)
end
|