Sha256: e1c2773bb834e6d1048698210c0a4ec4852f263032647a8074631ff838eda9f4
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true module Azeroth class RequestHandler # @api private # # hadler for requests to create resources class Create < RequestHandler private # @private # # Creates and return an instance of the model # # creation uses the method +"#{model.name}_params"+ to # fetch all allowed attributes for creation # # @return [Object] def resource @resource ||= build_resource end # build resource for create # # @return [Object] def build_resource @resource = collection.build(attributes) controller.instance_variable_set("@#{model.name}", resource) trigger_event(:save) do resource.tap(&:save) end end # @private # # Response status # # For success, returns +:created+, for # validation errors, it returns +:unprocessable_entity+ # # @return [Symbol] def status resource.valid? ? :created : :unprocessable_entity end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
azeroth-0.7.0 | lib/azeroth/request_handler/create.rb |