Module: Archangel::Controllers::ResourcefulConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Backend::ResourcefulConcern
- Defined in:
- app/controllers/concerns/archangel/controllers/resourceful_concern.rb
Overview
Resourceful concern
Instance Method Summary collapse
-
#create ⇒ Object
Create resource.
-
#destroy ⇒ Object
Destroy resource.
-
#edit ⇒ Object
Edit resource.
-
#index ⇒ Object
Resources.
-
#new ⇒ Object
New resource.
-
#show ⇒ Object
Resource.
-
#update ⇒ Object
Update resource.
Instance Method Details
#create ⇒ Object
Create resource
Formats
HTML, JSON
Request
POST /resources
POST /resources.json
Paramaters
{
"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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
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 |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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
Paramaters
{
"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 |