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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 http://api.rubyonrails.org/classes/ActionController/Base.html#M000267 and it looks like you could the image inline similar to this article I guess: http://railsforum.com/viewtopic.php?pid=19787 <SNIP> 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 </SNIP> Hope that helps... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 17, 9:37 am, Luke Pearce <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > > http://api.rubyonrails.org/classes/ActionController/Base.html#M000267 > > and it looks like you could the image inline similar to this article I > guess: > > http://railsforum.com/viewtopic.php?pid=19787 > > <SNIP> > 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 > </SNIP> > > 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 :) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 9/17/07, sparkane <sean.standish-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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. > 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.bodyThe 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. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---