Skip to content

Instantly share code, notes, and snippets.

@murajun1978
Last active August 29, 2015 14:05
Show Gist options
  • Save murajun1978/bf868bfe10f507bbda1f to your computer and use it in GitHub Desktop.
Save murajun1978/bf868bfe10f507bbda1f to your computer and use it in GitHub Desktop.
気持ち悪いコード
def create
# リファクタリング後
@staff = Staff.new(params[:staff])
if staff = Staff.find_by(email: @staff.email)
session[:staff_id] = staff.id
redirect :root
else
render :new
end
end
def create
# リファクタリング後
@staff = Staff.new(params[:staff])
render :new and return if @staff.email.blank?
staff = Staff.find_by(email: @staff.email)
session[:staff_id] = staff.id
redirect :root
end
def create
@staff = Staff.new(params[:staff])
if @staff.email.present?
staff = Staff.find_by(email: @staff.email)
end
if staff
session[:staff_id] = staff.id
redirect :root
else
render :new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment