0
add_column :issues, :data, :binary, :limit => 1.megabyte
get '/issues/:id/show_image' => 'issues#show_image', as: 'show_image_issue'
def show_image
    @issue = Issue.find(params[:id])
    send_data @issue.data, :type => 'image/png', :disposition => 'inline'
end
<%= f.file_field :data, as: :file %>
<%= image_tag show_image_issue_path(@issue) %>

The page loads and no errors, but there's no image.

1 Answers1

0

I recommend for you to use PaperClip or CarrierWave for storing images, storing binary data has many disadvantages.

PaperClip: https://github.com/thoughtbot/paperclip

CarrierWave: https://github.com/carrierwaveuploader/carrierwave

why? read here : Storing Images in DB - Yea or Nay?

if you insist to do this then you can try:-

<img src="<%= @issue.data %>" />

  • The insisted method doesn't work, and I'm trying to use PaperClip, but changing to `has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"` and to `add_attachment :users, :avatar` for `<%= image_tag @user.avatar.url %>` doesn't seem to be enough to fix it. – Aden Handasyde May 27 '19 at 23:45
  • you should save your image in the database as base64 string, looks like you are saving it as binary HTML has nothing to do with binary, also could you provide me with the error you have when you are using PaperClip – Tariq Mamdouh May 29 '19 at 02:09