Class: Bitia::ApiController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ActionController::MimeResponds, Resourceable
Defined in:
app/controllers/bitia/api_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



37
38
39
40
# File 'app/controllers/bitia/api_controller.rb', line 37

def create
  pure_create_or_update
  render
end

#destroyObject



47
48
49
50
51
52
# File 'app/controllers/bitia/api_controller.rb', line 47

def destroy
  authorize resource
  resource.destroy!

  render
end

#indexObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/bitia/api_controller.rb', line 14

def index
  all = resources.count
  if params.include? :offset
    instance_variable_set("@#{resources_name}", resources.offset(params[:offset]))
  end
  if params.include? :limit
    instance_variable_set("@#{resources_name}", resources.limit(Integer(params[:limit])))
  end
  [:all] = all unless [:all]

  render
end

#newObject



27
28
29
30
# File 'app/controllers/bitia/api_controller.rb', line 27

def new
  authorize resource
  render
end

#pure_filter(param) ⇒ Object



54
55
56
57
58
# File 'app/controllers/bitia/api_controller.rb', line 54

def pure_filter(param)
  return unless params[param].present?

  instance_variable_get("@#{resources_name}").where!(param => params[param])
end

#showObject



32
33
34
35
# File 'app/controllers/bitia/api_controller.rb', line 32

def show
  authorize resource
  render
end

#updateObject



42
43
44
45
# File 'app/controllers/bitia/api_controller.rb', line 42

def update
  pure_create_or_update
  render
end