Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwim/d9197aa2a1b4f3f57badfaca58242f69 to your computer and use it in GitHub Desktop.
Save pwim/d9197aa2a1b4f3f57badfaca58242f69 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