I’m using REST to serve content (images and SWFs) to a flash-file.
Depending on the IP of the user, I would like to serve different
content. To get the IP I use 'request.remote_ip, followed by an if
statement to return the correct content.
What I don’t know is how do I serve just the content (no XML, just
content.jpg) as a reply from my Rails-controller? The content is not
stored in a database, but in my public directory.
def show
ip = request.remote_ip
if ip=x
return '/content/hello.jpg'
else
return '/content/goodbye.jpg'
end
respond_to do |format|
format.html # bbprivat.html.erb
format.xml { render :xml => @ip }
end
you can use the send_file command to return binary data to the client
e.g.
respond_to do |format|
format.html { ip == x ? send_file ‘/content/hello.jpg’, :filename =>
‘hello.jpg’ : send_file ‘/content/goodbye.jpg’, :filename =>
‘goodbye.jpg’ }
end
think that will work , you might want to register a new content type
for the respond_to block so it ‘responds_to’ .jpg as well.
Anyone know how make Rails understand to use the public-folder as root?
Also, since I get plenty of weird characters on screen, rather than the
actual swf-file, I suppose I need to register swf to work with the
respond_to block.