Skip to content

Commit

Permalink
Use builtin Rails method
Browse files Browse the repository at this point in the history
  • Loading branch information
dacook committed Jun 15, 2023
1 parent a46917a commit d195882
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def show
end

def create
@customer = Customer.find_or_new(customer_params[:email], customer_params[:enterprise_id])
@customer = Customer.find_or_initialize_by(customer_params.slice(:email, :enterprise_id))

if user_can_create_customer?
@customer.created_manually = true
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def show

def create
authorize! :update, Enterprise.find(customer_params[:enterprise_id])
customer = Customer.find_or_new(customer_params[:email], customer_params[:enterprise_id])
customer = Customer.find_or_initialize_by(customer_params.slice(:email, :enterprise_id))
customer.assign_attributes(customer_params)

if customer.save
Expand Down
5 changes: 0 additions & 5 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class Customer < ApplicationRecord

attr_accessor :gateway_recurring_payment_client_secret, :gateway_shop_id

def self.find_or_new(email, enterprise_id)
Customer.find_by(email: email, enterprise_id: enterprise_id) ||
Customer.new(email: email, enterprise_id: enterprise_id)
end

def full_name
"#{first_name} #{last_name}".strip
end
Expand Down

0 comments on commit d195882

Please sign in to comment.