Send_data with a layout?

Hello,

I’m using send_data to retrieve binary (images) from the database.

It works fine, this is my controller :

@picture = Picture.find(params[:id])
@image = @picture.image_file
send_data (@image, :type => @picture.image_content_type, :filename =>
@picture.image_file_name, :disposition => ‘inline’)

However, when a user navigates to that action, all it shows is a
picture. Is
there a way to render the* layout *as well, and have the send_data put
the
picture in a layout? instead of just displaying a picture?

ie Could I have the send_data place it in the <%= yield %> ?

-David Z.

Bingo!

No need for send_data in the first place.

This was all i needed, in the view: <%=
image_tag("/pictures/#{@picture.id}", :alt => “Image”) %>

Now the image displays inside a layout. Sweet.

On 17 Feb 2011, at 15:34, David Z. wrote:

picture. Is there a way to render the layout as well, and have the
send_data put the picture in a layout? instead of just displaying a
picture?

ie Could I have the send_data place it in the <%= yield %> ?

That’s not how it works. If you want your picture to be in a HTML
layout, you’ll need to make a controller that serves a HTML page with
the image in it, i.e.
image_tag(url_for_your_image_like_mentioned_above). That image tag
will then query your image controller (the one where you send that
data from) for the picture. send_data does exactly what it says: it
sends the image data over, nothing more.

Best regards

Peter De Berdt