Module: Archangel::Controllers::ResourcefulConcern

Extended by:
ActiveSupport::Concern
Included in:
Backend::AssetsController, Backend::CollectionsController, Backend::DesignsController, Backend::EntriesController, Backend::PagesController, Backend::UsersController, Backend::WidgetsController
Defined in:
app/controllers/concerns/archangel/controllers/resourceful_concern.rb

Overview

Resourceful concern

Instance Method Summary collapse

Instance Method Details

#createObject

Create resource

Formats

HTML, JSON

Request

POST /resources
POST /resources.json

Parameters

{
  "resource": {
    "id": 123,
    ...
  }
}

110
111
112
113
114
115
116
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 110

def create
  resource = resource_new_content

  resource.save unless resource.blank?

  respond_with resource, location: -> { location_after_create }
end

#destroyObject

Destroy resource

Formats

HTML, JSON

Params

[Integer] id - the resource ID

Request

DELETE /resources/:id
DELETE /resources/:id.json

189
190
191
192
193
194
195
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 189

def destroy
  resource = resource_content

  resource.destroy unless resource.blank?

  respond_with resource, location: -> { location_after_destroy }
end

#editObject

Edit resource

Formats

HTML, JSON

Params

[Integer] id - the resource ID

Request

GET /resources/:id/edit
GET /resources/:id/edit.json

Response

{
  "id": 123,
  ...
  "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
}

139
140
141
142
143
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 139

def edit
  resource = resource_content

  respond_with resource
end

#indexObject

Resources

Formats

HTML, JSON

Request

GET /resources
GET /resources.json

Response

[
  {
    "id": 123,
    ...
    "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
    "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
  },
  ...
]

35
36
37
38
39
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 35

def index
  resources = resources_content

  respond_with resources
end

#newObject

New resource

Formats

HTML, JSON

Request

GET /resources/new
GET /resources/new.json

Response

{
  "id": null,
  ...
  "created_at": null,
  "updated_at": null
}

86
87
88
89
90
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 86

def new
  resource = resource_new_content

  respond_with resource
end

#showObject

Resource

Formats

HTML, JSON

Params

[Integer] id - the resource ID

Request

GET /resources/:id
GET /resources/:id.json

Response

{
  "id": 123,
  ...
  "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
}

62
63
64
65
66
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 62

def show
  resource = resource_content

  respond_with resource
end

#updateObject

Update resource

Formats

HTML, JSON

Params

[Integer] id - the resource ID

Request

PATCH /resources/:id
PATCH /resources/:id.json
PUT   /resources/:id
PUT   /resources/:id.json

Parameters

{
  "resource": {
    "id": 123,
    ...
  }
}

168
169
170
171
172
173
174
# File 'app/controllers/concerns/archangel/controllers/resourceful_concern.rb', line 168

def update
  resource = resource_content

  resource.update(resource_params)

  respond_with resource, location: -> { location_after_update }
end