Bypassing normal template rendering?

I have an app that let’s a user design a label and see a preview in
realtime.

The setup:

The image is generated on a second machine, not the webserver. This
second machine is not accessible from the internet, but only from the
main webserver, so I can’t call it directly in my app. The generated
image has to travel between the two machines before going to the
client proper. The first machines gets the image from the second
machine using an HTTP request.

The issue:

Ideally I’d like to be able just to pass the generated image - which
is received over HTTP - directly back to the user client without
messing with it. As it is requested over HTTP in the first place, it
can be passed back directly, the main webserver just acting as a
conduit. The problem is that in RoR, if I use, say, a controller
action to call the 2d machine to get the image, RoR wants to render
the default template, “fetch_preview” in this case. I think this will
change the response from the image-response received from the 2nd
machine, to a ‘text/html’ response. What I’d like to know is if it’s
possible either to (a) tell RoR to just skip the template rendering
entirely for the “fetch_preview” action, skip making a template, and
just “put” the response from the 2d machine back to the client; or (b)
change how the template rendering works so that it sends the data back
as an image.

Here’s my code that fetches and sends the image - it’s pretty much
boilerplate, but for what it’s worth:
require ‘net/http’
require ‘uri’

url = URI.parse( “http://[url]/image_maker.cgi?
img_tid=#{ session[ :img_id ] }&preview=1” )
req = Net::HTTP::Get.new( url.path )
res = Net::HTTP.start( url.host, url.port ) { |http|
http.request( req ) }
puts res.body

On Sep 17, 9:37 am, Luke P. [email protected]
wrote:

  1. @image = @image_data.binary_data
  2. send_data (@image, :type => @image_data.content_type,
  3.                  :filename => @image_data.filename,
    
  4.                  :disposition => 'inline')
    
  5. end

Hope that helps…

Thanks Luke, my problem has advanced from the rendering to getting the
browser to display the image properly. Investigating send_data
options :slight_smile:

What I’d like to know is if it’s
possible either to (a) tell RoR to just skip the template rendering
entirely for the “fetch_preview” action, skip making a template, and
just “put” the response from the 2d machine back to the client; or (b)
change how the template rendering works so that it sends the data back
as an image.

Well you can skip the template rendering via

render :nothing => true

and it looks like you could the image inline similar to this article I
guess:

http://railsforum.com/viewtopic.php?pid=19787

1. def code_image 2. @image_data = Photo.find(params[:id]) 3. @image = @image_data.binary_data 4. send_data (@image, :type => @image_data.content_type, 5. :filename => @image_data.filename, 6. :disposition => 'inline') 7. end

Hope that helps…

On 9/17/07, sparkane [email protected] wrote:

client proper. The first machines gets the image from the second
http.request( req ) }
puts res.body

The fact that the data is coming from another web server is
irrelevant. You are sending out binary data, so you need to use
send_data() and set the appropriate mime type (which you can get from
the Net::HTTP response). send_data skips() the normal template
rendering.