Module: Trax::Controller::Actions
- Extended by:
- ActiveSupport::Concern
- Included in:
- Trax::Controller
- Defined in:
- lib/trax/controller/actions.rb
Instance Method Summary collapse
-
#create(success_status: 201, failure_status: :unprocessable_entity, **options) ⇒ Object
setting resource ivar stops it from trying to create via the default behavior.
- #destroy(success_status: 200, failure_status: :method_not_allowed, **options) ⇒ Object
- #index(collection: _collection, meta: collection_response_meta, serializer: collection_serializer, root: collection_root) ⇒ Object
- #show(*args, **options) ⇒ Object
- #update(success_status: 200, failure_status: :unprocessable_entity, **options) ⇒ Object
Instance Method Details
#create(success_status: 201, failure_status: :unprocessable_entity, **options) ⇒ Object
setting resource ivar stops it from trying to create via the default behavior
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trax/controller/actions.rb', line 18 def create(success_status:201, failure_status: :unprocessable_entity, **) set_resource_ivar([:resource]) if .has_key?(:resource) create! do |success, failure| success.json do render_resource(success_status, **) end failure.json do render_errors(failure_status, **) end end end |
#destroy(success_status: 200, failure_status: :method_not_allowed, **options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trax/controller/actions.rb', line 46 def destroy(success_status:200, failure_status: :method_not_allowed, **) set_resource_ivar([:resource]) if .has_key?(:resource) destroy! do |success, failure| success.json do render_resource(success_status, **) end failure.json do render_errors(failure_status, **) end end end |
#index(collection: _collection, meta: collection_response_meta, serializer: collection_serializer, root: collection_root) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/trax/controller/actions.rb', line 10 def index(collection: _collection, meta: , serializer: collection_serializer, root: collection_root) render :json => collection, :meta => , :each_serializer => serializer, :root => root end |
#show(*args, **options) ⇒ Object
60 61 62 |
# File 'lib/trax/controller/actions.rb', line 60 def show(*args, **) render_resource(*args, **) end |
#update(success_status: 200, failure_status: :unprocessable_entity, **options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trax/controller/actions.rb', line 32 def update(success_status:200, failure_status: :unprocessable_entity, **) set_resource_ivar([:resource]) if .has_key?(:resource) update! do |success, failure| success.json do render_resource(success_status, **) end failure.json do render_errors(failure_status, **) end end end |