How to convert BinaryString to save in ImageFile at public path

Hello I need your help and expertise,

I have a method_name called avatar which will pull data to the web and
the photo object from the Binary String.

def avatar
@ja = Model.where(“id” => params[:id]).limit(1).first
if @ja.avatar && @ja.avatar.photo_binary
send_data @ja.avatar.photo_binary, :type => @ja.avatar.content_type,
:disposition => ‘inline’
path = “#{Rails.root}/public/images/default_avatar.png”
send_file path, :type => “images/png”, :disposition => ‘inline’

in my show action page i load the image correctly
= image_tag avatar_job_job_application_path(@job, @job_application),
:class => “avatar”

#This will show the photo but the url will absolutely show like
because it was parse by the avatar method

Now, at the same time I want the show action to save the BinaryString to
the filesystem as an image file. Like for example XXXX.jpg inside so
that I can call the file direcltly

Now it is a BinaryString that I want to save it temporarily in the

How can I do that? Any suggestions guys?