开发者

Rails 3 Rendering Binary Content

开发者 https://www.devze.com 2023-03-10 04:14 出处:网络
I need to render binary开发者_如何学运维 content(images) on web page. I\'m saving images in the database with datatype binary. Now I need to iterate available images from the database and render on we

I need to render binary开发者_如何学运维 content(images) on web page. I'm saving images in the database with datatype binary. Now I need to iterate available images from the database and render on webpage.

Please check the below code that I'm doing. Icon is the image column name in material.

// iterating all materials
<% @materials.each do |material| %>
     // for each material
     <span><%= image_tag(material.icon) %></span>
<% end %>

Any help would be greatly appreciated..


You need to add an action to your controller along these lines (cribbed from here):

def image
    @material = Material.find(params[:id])
    send_data @material.icon, :type => 'image/png',:disposition => 'inline'
end

Then call the path to that action in your image_tag. You obviously need to make sure the :type field has the right MIME type, add a route, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消