Class: HyperAdmin::ResourceController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hyper_admin/resource_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/hyper_admin/resource_controller.rb', line 34

def create
  @resource = @resource_class.new params[@resource_class.model_name.param_key]

  if @resource.save
    render json: @resource
  else
    render json: @resource.errors, status: 422
  end
end

#destroyObject



54
55
56
57
58
59
60
# File 'app/controllers/hyper_admin/resource_controller.rb', line 54

def destroy
  @resource = @resource_class.find params[:id]

  @resource.destroy

  head 200
end

#editObject



26
27
28
29
30
31
32
# File 'app/controllers/hyper_admin/resource_controller.rb', line 26

def edit
  @resource = resource
  @attributes = @resource.attributes.delete_if do |k, v|
    k.to_sym.in? [ :id, :created_at, :updated_at ]
  end
  render 'admin/resources/edit'
end

#indexObject



8
9
10
11
# File 'app/controllers/hyper_admin/resource_controller.rb', line 8

def index
  @resources = resource_class.all
  render 'admin/resources/index'
end

#newObject



18
19
20
21
22
23
24
# File 'app/controllers/hyper_admin/resource_controller.rb', line 18

def new
  @resource = resource_class.new
  @attributes = @resource.attributes.delete_if do |k, v|
    k.to_sym.in? [ :id, :created_at, :updated_at ]
  end
  render 'admin/resources/new'
end

#resourceObject



62
63
64
# File 'app/controllers/hyper_admin/resource_controller.rb', line 62

def resource
  resource_class.find params[:id]
end

#resource_classObject



66
67
68
# File 'app/controllers/hyper_admin/resource_controller.rb', line 66

def resource_class
  raise "This method must be overridden"
end

#showObject



13
14
15
16
# File 'app/controllers/hyper_admin/resource_controller.rb', line 13

def show
  @resource = resource
  render 'admin/resources/show'
end

#updateObject



44
45
46
47
48
49
50
51
52
# File 'app/controllers/hyper_admin/resource_controller.rb', line 44

def update
  @resource = @resource_class.find params[:id]

  if @resource.update params[@resource_class.model_name.param_key]
    render json: @resource
  else
    render json: @resource.errors, status: 422
  end
end