Forked from Killavus/after_removing_callbacks_controller.rb
Created
May 4, 2016 08:41
-
-
Save pwim/d9197aa2a1b4f3f57badfaca58242f69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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