Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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