views:

66

answers:

1

Hi, I'm building a Rails app that does conversion tracking on outside sites. I'd like to allow users to paste an image tag in their conversion pages (like AdWords), and whenever that image is requested, a conversion registers in my app.

respond_to do |format|
  if @conversion.save
    flash[:notice] = 'Conversion was successfully created.'
    format.html { redirect_to(@conversion) }
    format.xml  { render :xml => @conversion, :status => :created, :location => @conversion }
    format.js { render :json => @conversion, :status => :created }
    format.gif { head :status => :ok }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @conversion.errors, :status => :unprocessable_entity }
  end
end    

This way, the browser gets a non-existent .gif image. Is there a better way to do this?

+1  A: 

Simple option:

format.gif { redirect_to '/images/1x1.gif' }

I think in /really/ old browsers (IE5, Netscape maybe?) this may not work, so if you need to support those, the old school solution was to actually load in the binary data of the gif and spit it out back to the browser directly with the correct content type.

Gal