Files
grecia/app/controllers/management/document_verifications_controller.rb
rgarcia bb3c4c6399 adds consistency to ruby code style
Keep a blank line before and after private
Keep a blank line before and after protected
Remove extra empty line at class body end
Remove extra blank line
Add final newline
Use 2 (not 3) spaces for indentation
Use 2 (not 4) spaces for indentation
Remove space before comma
Add space after comma
Remove trailing whitespaces
Remove unnecessary spacing
Use snake_case for variable names
Do not use then for multi-line if
Remove unused block argument - i
Use the new Ruby 1.9 hash syntax
Remove unused assignment to variable
Indent when as deep as case
Align attributes
Align end with def
2016-11-15 11:18:43 +01:00

49 lines
1.5 KiB
Ruby

class Management::DocumentVerificationsController < Management::BaseController
before_action :clean_document_number, only: :check
before_action :set_document, only: :check
def index
@document_verification = Verification::Management::Document.new()
end
def check
@document_verification = Verification::Management::Document.new(document_verification_params)
if @document_verification.valid?
if @document_verification.verified?
render :verified
elsif @document_verification.user?
render :new
elsif @document_verification.in_census?
redirect_to new_management_email_verification_path(email_verification: document_verification_params)
else
render :invalid_document
end
else
render :index
end
end
def create
@document_verification = Verification::Management::Document.new(document_verification_params)
@document_verification.verify
render :verified
end
private
def document_verification_params
params.require(:document_verification).permit(:document_type, :document_number)
end
def set_document
session[:document_type] = params[:document_verification][:document_type]
session[:document_number] = params[:document_verification][:document_number]
end
def clean_document_number
params[:document_verification][:document_number] = params[:document_verification][:document_number].gsub(/[^a-z0-9]+/i, "").upcase unless params[:document_verification][:document_number].blank?
end
end