Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Killavus/c0b5d2de9e687f11b7dac2689afc891b to your computer and use it in GitHub Desktop.
Save Killavus/c0b5d2de9e687f11b7dac2689afc891b to your computer and use it in GitHub Desktop.
class CustomersController < ApplicationController
# …
def create
if auto_create_request?
@customer = Customer.auto_create(customer_params)
else
@customer = Customer.register(customer_params)
end
respond_to do |format|
format.html { redirect_to @customer,
notice: 'Customer was successfully created.' }
format.json { render :show, status: :created,
location: @customer }
end
rescue ActiveRecord::RecordInvalid
respond_to do |format|
format.html { render :new }
format.json { render json: @customer.errors,
status: :unprocessable_entity }
end
end
def auto_create_request?
customer_params[:auto_created].present?
end
# …
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment