Module: RESTFramework::CreateModelMixin

Included in:
ModelControllerMixin
Defined in:
lib/rest_framework/controller_mixins/models.rb

Overview

Mixin for creating records.

Instance Method Summary collapse

Instance Method Details

#createObject



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/rest_framework/controller_mixins/models.rb', line 202

def create
  if self.get_recordset.respond_to?(:create!) && !self.disable_creation_from_recordset
    # Create with any properties inherited from the recordset (like associations).
    @record = self.get_recordset.create!(self.get_create_params)
  else
    # Otherwise, perform a "bare" create.
    @record = self.get_model.create!(self.get_create_params)
  end
  serialized_record = self.get_serializer_class.new(object: @record, controller: self).serialize
  return api_response(serialized_record)
end