Class: Para::Admin::ResourcesController

Inherits:
BaseController show all
Includes:
Helpers::AttributesMappings, ModelHelper
Defined in:
app/controllers/para/admin/resources_controller.rb

Instance Method Summary collapse

Methods included from Helpers::AttributesMappings

#attributes_mappings_for

Methods included from ModelHelper

#attribute_field_mappings_for, #excerpt_value_for, #field_for, #field_value_for, #model_field_mappings, #relation_klass_for, #value_for

Methods inherited from BaseController

#current_ability, #current_admin

Methods included from BaseHelper

#find_partial_for, #find_relation_name_for, #flash_message, #registered_components_options, #resource_title_for, #template_path_lookup

Methods included from Helpers::ResourceName

#resource_name

Methods inherited from Para::ApplicationController

#admin?

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/para/admin/resources_controller.rb', line 17

def create
  # Assign component the resource belongs to it
  resource.component = @component if resource.respond_to?(:component=)

  # We overriden Cancan so it does not try to assign our params during the
  # create action, allowing our attribute fields to parse them with an
  # actual resource.
  resource.assign_attributes(resource_params)

  if resource.save
    flash_message(:success, resource)
    redirect_to after_form_submit_path, status: 303
  else
    flash_message(:error, resource)
    render 'new', status: 422
  end
end

#destroyObject



49
50
51
52
53
# File 'app/controllers/para/admin/resources_controller.rb', line 49

def destroy
  resource.destroy
  flash_message(:success, resource)
  redirect_to after_form_submit_path, status: 303
end

#editObject



35
36
37
# File 'app/controllers/para/admin/resources_controller.rb', line 35

def edit
  render 'para/admin/resources/edit'
end

#newObject



13
14
15
# File 'app/controllers/para/admin/resources_controller.rb', line 13

def new
  render 'para/admin/resources/new'
end

#orderObject



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

def order
  ActiveRecord::Base.transaction do
    resources_data.each do |resource_params|
      resource = resources_hash[resource_params[:id]]
      resource.position = resource_params[:position].to_i
      resource.save(validate: false)
    end
  end

  head 200
end

#treeObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/para/admin/resources_controller.rb', line 67

def tree
  ActiveRecord::Base.transaction do
    resources_data.each do |resource_params|
      resource = resources_hash[resource_params[:id]]
      resource.assign_attributes(
        position: resource_params[:position].to_i,
        parent_id: resource_params[:parent_id]
      )
      resource.save(validate: false)
    end
  end

  head 200
end

#updateObject



39
40
41
42
43
44
45
46
47
# File 'app/controllers/para/admin/resources_controller.rb', line 39

def update
  if resource.update(resource_params)
    flash_message(:success, resource)
    redirect_to after_form_submit_path, status: 303
  else
    flash_message(:error, resource)
    render 'edit', status: 422
  end
end