Class: Cdx::Admin::ResourceController

Inherits:
BaseController show all
Defined in:
app/controllers/cdx/admin/resource_controller.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseController

#authenticate_admin_user!, #current_ability, #meta_title

Methods inherited from Cdx::ApplicationController

#current_ability

Methods included from ControllerHelpers::Settings

#current_settings

Methods included from ControllerHelpers::Seo

#canonical_url, #contextual_record, #meta_data, #meta_title, #open_graph_data

Class Attribute Details

.parent_dataObject

Returns the value of attribute parent_data.



55
56
57
# File 'app/controllers/cdx/admin/resource_controller.rb', line 55

def parent_data
  @parent_data
end

Class Method Details

.belongs_to(model_name, options = {}) ⇒ Object



57
58
59
60
61
62
# File 'app/controllers/cdx/admin/resource_controller.rb', line 57

def belongs_to(model_name, options = {})
  @parent_data ||= {}
  @parent_data[:model_name]  = model_name
  @parent_data[:model_class] = model_name.to_s.classify.constantize
  @parent_data[:find_by]     = options[:find_by] || :id
end

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
# File 'app/controllers/cdx/admin/resource_controller.rb', line 32

def create
  if @object.update permitted_resource_params
    flash_message(@object, :create, :success)
    redirect_to location_after_save
  else
    flash_message(@object, :create, :error)
    render :new
  end
end

#destroyObject



42
43
44
45
46
47
48
49
50
# File 'app/controllers/cdx/admin/resource_controller.rb', line 42

def destroy
  if @object.destroy
    flash_message(@object, :destroy, :success)
  else
    flash_message(@object, :destroy, :error)
  end

  redirect_to location_after_destroy
end

#editObject



19
20
# File 'app/controllers/cdx/admin/resource_controller.rb', line 19

def edit
end

#indexObject



12
13
14
# File 'app/controllers/cdx/admin/resource_controller.rb', line 12

def index
  @collection = @collection.page(params[:page])
end

#newObject



16
17
# File 'app/controllers/cdx/admin/resource_controller.rb', line 16

def new
end

#updateObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/cdx/admin/resource_controller.rb', line 22

def update
  if @object.update permitted_resource_params
    flash_message(@object, :update, :success)
    redirect_to location_after_save
  else
    flash_message(@object, :update, :error)
    render :edit
  end
end