:create
General Setup & Layout
Example Setup:
class ItemsController < ApplicationController
include QueryParamsProcessor
def create
# LOCAL HANDLING
##################
# Create a new item instance with permitted parameters
@item = Item.new(item_params)
# Associate the item with the currently active company
@item.company = get_current_company
# Handle any other associations or initial setup
# For example, if there's user information to be added
@item.user = current_user if defined?(current_user)
# ABSTRACTED/REUSABLE HANDLING (e.g. Concerns, etc.)
##################
# CONCERNS
# Maybe there's a concern for handling attachments or images?
# @item = handle_attachments(@item)
# OTHER (?)
# ...
# EXECUTE & RESPOND
##################
# Save the item and render response
if @item.save
render json: @item, status: :created
else
render json: @item.errors, status: :unprocessable_entity
end
end
# ... Other actions ...
private
def item_params
params.require(:item).permit(:name, :description, :type, ...other permitted attributes...)
end
end
Last updated