Class: Alchemy::Admin::ResourcesController

Inherits:
BaseController show all
Includes:
ResourcesHelper
Defined in:
app/controllers/alchemy/admin/resources_controller.rb

Constant Summary collapse

COMMON_SEARCH_FILTER_EXCLUDES =
[:id, :utf8, :_method, :_, :format].freeze

Instance Method Summary collapse

Methods included from ResourcesHelper

#contains_relations?, #edit_resource_path, #new_resource_path, #render_attribute, #render_resources, #resource_attribute_field_options, #resource_filter_select, #resource_has_filters, #resource_has_tags, #resource_instance_variable, #resource_model, #resource_name, #resource_path, #resource_relations_names, #resource_scope, #resource_url_proxy, #resource_window_size, #resources_header, #resources_instance_variable, #resources_path, #sortable_resource_header_column

Methods inherited from BaseController

#leave

Methods included from Modules

included, #module_definition_for, register_module

Methods included from Alchemy::AbilityHelper

#current_ability

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?, #prefix_locale?

Instance Method Details

#createObject


60
61
62
63
64
65
66
67
68
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 60

def create
  instance_variable_set("@#{resource_handler.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

#destroyObject


79
80
81
82
83
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 79

def destroy
  resource_instance_variable.destroy
  flash_notice_for_resource_action
  do_redirect_to resource_url_proxy.url_for(search_filter_params.merge(action: 'index'))
end

#editObject


58
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 58

def edit; end

#indexObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 23

def index
  @query = resource_handler.model.ransack(search_filter_params[:q])
  items = @query.result

  if contains_relations?
    items = items.includes(*resource_relations_names)
  end

  if search_filter_params[:tagged_with].present?
    items = items.tagged_with(search_filter_params[:tagged_with])
  end

  if search_filter_params[:filter].present?
    items = items.public_send(sanitized_filter_params)
  end

  respond_to do |format|
    format.html {
      items = items.page(params[:page] || 1).per(items_per_page)
      instance_variable_set("@#{resource_handler.resources_name}", items)
    }
    format.csv {
      instance_variable_set("@#{resource_handler.resources_name}", items)
    }
  end
end

#newObject


50
51
52
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 50

def new
  instance_variable_set("@#{resource_handler.resource_name}", resource_handler.model.new)
end

#resource_handlerObject


85
86
87
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 85

def resource_handler
  @_resource_handler ||= Alchemy::Resource.new(controller_path, alchemy_module)
end

#showObject


54
55
56
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 54

def show
  render action: 'edit'
end

#updateObject


70
71
72
73
74
75
76
77
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 70

def update
  resource_instance_variable.update_attributes(resource_params)
  render_errors_or_redirect(
    resource_instance_variable,
    resources_path(resource_instance_variable.class, search_filter_params),
    flash_notice_for_resource_action
  )
end