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 Zhu -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 Feb 2011, at 15:34, David Zhu wrote:> 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 %> ?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.