Module: EIVO::Concerns::Resources
- Extended by:
- ActiveSupport::Concern
- Includes:
- Pagination
- Defined in:
- app/controllers/eivo/concerns/resources.rb
Instance Method Summary
collapse
Methods included from Pagination
#paginate, #pagination_options
Instance Method Details
#create ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/eivo/concerns/resources.rb', line 39
def create
@object ||= collection.new
@object.assign_attributes(object_params_create)
if @object.save
render_success serializer.new(@object, @serializer_options)
else
render_model_errors @object.errors
end
end
|
#destroy ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/eivo/concerns/resources.rb', line 61
def destroy
@object ||= collection.find(params[:id])
if @object.destroy
render_success
else
render_model_errors @object.errors
end
end
|
#index(options = {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/eivo/concerns/resources.rb', line 14
def index(options = {})
@objects ||= collection_index
@objects = paginate(@objects) unless options[:paginate] == false
if options[:cache] && options[:cache] != false
cache_options = if options[:cache].is_a?(Hash)
options[:cache]
else
{}
end
if stale?(@objects, public: cache_options.fetch(:public, false))
render_success serializer.new(@objects, @serializer_options)
end
else
render_success serializer.new(@objects, @serializer_options)
end
end
|
#show ⇒ Object
34
35
36
37
|
# File 'app/controllers/eivo/concerns/resources.rb', line 34
def show
@object ||= collection_show.find(params[:id])
render_success serializer.new(@object, @serializer_options)
end
|
#update ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/eivo/concerns/resources.rb', line 50
def update
@object ||= collection.find(params[:id])
@object.assign_attributes(object_params_update)
if @object.save
render_success serializer.new(@object, @serializer_options)
else
render_model_errors @object.errors
end
end
|