Module: RESTFramework::CreateModelMixin
- Included in:
- ModelControllerMixin
- Defined in:
- lib/rest_framework/controller_mixins/models.rb
Overview
Mixin for creating records.
Instance Method Summary collapse
- #create ⇒ Object
-
#create! ⇒ Object
Helper to perform the ‘create!` call and return the created record.
Instance Method Details
#create ⇒ Object
393 394 395 |
# File 'lib/rest_framework/controller_mixins/models.rb', line 393 def create return api_response(self.create!, status: :created) end |
#create! ⇒ Object
Helper to perform the ‘create!` call and return the created record.
398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/rest_framework/controller_mixins/models.rb', line 398 def create! if self.get_recordset.respond_to?(:create!) && self.create_from_recordset # Create with any properties inherited from the recordset. We exclude any `select` clauses in # case model callbacks need to call `count` on this collection, which typically raises a SQL # `SyntaxError`. return self.get_recordset.except(:select).create!(self.get_create_params) else # Otherwise, perform a "bare" create. return self.class.get_model.create!(self.get_create_params) end end |