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?, #edit_resource_path, #new_resource_path, #render_attribute, #resource_attribute_field_options, #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 ConfigurationMethods

#configuration, #multi_language?, #multi_site?

Instance Method Details

#createObject



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

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,
    flash_notice_for_resource_action
  )
end

#destroyObject



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

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

#editObject



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

def edit; end

#indexObject



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

def index
  items = resource_handler.model
  if contains_relations?
    items = items.includes(*resource_relations_names)
  end
  if params[:query].present?
    items = query_items(items)
  end
  items = items.order(sort_order)
  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



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

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

#resource_handlerObject



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

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

#showObject



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

def show
  render action: 'edit'
end

#updateObject



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

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