Files
baclight/app/controllers/id_card/employer_logos_controller.rb
T

56 lines
1.2 KiB
Ruby

class IdCard::EmployerLogosController < ApplicationController
def index
end
def show
end
def image
logo_file = IdCard::EmployerLogo.find(params[:id])
puts params[:id]
logo_binary = logo_file.image_data
logo_filename = logo_file.filename
send_data logo_binary,
filename: logo_filename,
disposition: 'inline'
end
def new
end
def create
file = card_logo_file_params["logo_file"]
if file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
filename = file.original_filename
# binary_data = file.read
binary_data = File.binread(file)
meme_type = Marcel::MimeType.for(file)
employerlogo = IdCard::EmployerLogo.create(
filename: filename,
image_data: binary_data,
content_type: meme_type
)
render json: employerlogo, only: [:id], status: :ok
end
end
def edit
end
def update
end
def destroy
end
private
def card_logo_file_params
params.require(:card_logo_file).permit(:logo_file, :logo_type)
end
end