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
shows
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'
  else
    path = "#{Rails.root}/public/images/default_avatar.png"
  send_file path, :type => "images/png", :disposition => 'inline'
  end
end

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
/JDXXXXX/ja/JPXXXXX/avatar
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. Life 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
#{Rails.root}/public/assets/XXX.jpg

How can I do that? Any suggestions guys?

Thanks!
Andre