Class: BaseApiController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- BaseApiController
- Defined in:
- lib/baseapi/app/controllers/base_api_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /models/id.json.
-
#destroy ⇒ Object
DELETE /models/id.json.
-
#index ⇒ Object
GET /models.json.
-
#show ⇒ Object
GET /models/id.json.
-
#update ⇒ Object
PATCH/PUT /models/id.json.
Instance Method Details
#create ⇒ Object
POST /models/id.json
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 23 def create render 'model.json.jbuilder' if transaction(-> { self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym) params.each do |key, value| if key.present? and @Model.column_names.include?(key) @model.send("#{key}=", value) end end @model.save self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym) }) end |
#destroy ⇒ Object
DELETE /models/id.json
55 56 57 58 59 60 61 |
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 55 def destroy render 'model.json.jbuilder' if transaction(-> { self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym) @model._destroy self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym) }) end |
#index ⇒ Object
GET /models.json
10 11 12 |
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 10 def index render 'models.json.jbuilder' end |
#show ⇒ Object
GET /models/id.json
16 17 18 |
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 16 def show render 'model.json.jbuilder' end |
#update ⇒ Object
PATCH/PUT /models/id.json
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 39 def update render 'model.json.jbuilder' if transaction(-> { self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym) params.each do |key, value| if key.present? and @Model.column_names.include?(key) @model.send("#{key}=", value) end end @model.save self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym) }) end |