Return 1x1.gif as an answer in Rails

I am creating a Rails application that monitors conversions on external sites. I would like to allow users to embed an image tag on their conversion pages (e.g. AdWords), and whenever this image is requested, a conversion is registered in my application.

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    

Thus, the browser receives a nonexistent .gif image. Is there a better way to do this?

+3
source share
3 answers

Simple option:

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

, // (, IE5, Netscape?) , , , , gif .

+3

, ,

:

http://forrst.com/posts/Render_a_1x1_Transparent_GIF_with_Rails-eV4

send_data(Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="), :type => "image/gif", :disposition => "inline")
+5

Here is my solution

format.gif { send_data Rails.root.join('app', 'assets', 'images', '1x1.gif') }
0
source

Source: https://habr.com/ru/post/1745553/


All Articles