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



242
243
244
# File 'lib/rest_framework/controller_mixins/models.rb', line 242

def create
  api_response(self.create!)
end

#create!Object



246
247
248
249
250
251
252
253
254
255
256
# File 'lib/rest_framework/controller_mixins/models.rb', line 246

def create!
  if self.get_recordset.respond_to?(:create!) && self.create_from_recordset
    # Create with any properties inherited from the recordset.
    @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

  return self.get_serializer_class.new(@record, controller: self).serialize
end