lib/azeroth/request_handler/update.rb in azeroth-0.2.0 vs lib/azeroth/request_handler/update.rb in azeroth-0.3.0
- old
+ new
@@ -15,13 +15,30 @@
# update uses the method +"#{model.name}_params"+ to
# fetch all allowed attributes for update
#
# @return [Object]
def resource
+ @resource ||= update_resource
+ end
+
+ def update_resource
attributes = controller.send("#{model.name}_params")
- resource = controller.send(model.name)
- resource.update(attributes)
- resource
+
+ controller.send(model.name).tap do |entry|
+ entry.update(attributes)
+ end
+ end
+
+ # @private
+ #
+ # Response status
+ #
+ # For success, returns +:ok+, for
+ # validation errors, it returns +:unprocessable_entity+
+ #
+ # @return [Symbol]
+ def status
+ resource.valid? ? :ok : :unprocessable_entity
end
end
end
end