Class: Alchemy::Admin::ResourcesController

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

Instance Method Summary collapse

Methods included from ResourcesHelper

#contains_relations?, #current_location_params, #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



57
58
59
60
61
62
63
64
65
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 57

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_handler.namespaced_resources_name, current_location_params),
    flash_notice_for_resource_action
  )
end

#destroyObject



76
77
78
79
80
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 76

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

#editObject



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

def edit; end

#indexObject



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

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

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

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

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

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

#newObject



47
48
49
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 47

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

#resource_handlerObject



82
83
84
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 82

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

#showObject



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

def show
  render action: 'edit'
end

#updateObject



67
68
69
70
71
72
73
74
# File 'app/controllers/alchemy/admin/resources_controller.rb', line 67

def update
  resource_instance_variable.update_attributes(resource_params)
  render_errors_or_redirect(
    resource_instance_variable,
    resources_path(resource_handler.namespaced_resources_name, current_location_params),
    flash_notice_for_resource_action
  )
end