Created
May 3, 2016 22:10
-
-
Save Killavus/c0b5d2de9e687f11b7dac2689afc891b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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