Radius tag and send_data method

Hy everybody,
how can I use the “send_data” method in a radius tag?

More details:
in a RoR application I’ve used the method “send_data” to download e file
stored in a database table in this way:

rhtml code:
<%= link_to ‘Download’, :action => ‘download’, :id => file_list.id %>

controller code:
def download
@file = FileList.find(params[:id])
@xml = @file.xmlfile #polymorphic associations
send_data(@xml.file, :type => “txt/xml”, :filename =>
“#{@file.filename}”)
end

It’s work fine, but now in my radiant extension I need a tag that do the
same thing. I’ve developed this tag:

tag “download” do |tag|

@file_id = request.parameters[:file]
@file = FileList.find(:all, :conditions => [ “id = ?”, @file_id ])
@file.each do |file|
send_data("#{file.xmlfile.file}", :type => “txt/xml”, :filename =>
“#{file.filename}”)
end
end

It returs me the error “undefined method send_data for #”

Anyone can help me?

Thanks and greatings

My first impression is that this is not directly possible in Radiant.

You could access the send_data() method of ActionController
indirectly
through an instance or class variable. The problem is that Radiant
will
try to render the page+layout and send it back to the user, so with the
“extra” send_data() you will get a double render error from Rails.

A solution is to do the send_data() in Rails code and modify the 

routes
so the download request get routed to an action/controller outside
Radiant.
You could do this with one of the existing rails-on-radiant extensions
available, or hack directly the Radiant code.

Anyway, it would be nice to have this send-data functionality packed 

in
a Radiant extension. It looks a nice feature to have.

/AITOR

Don’t use send_data! Especially if you’re streaming a large file!

Using send_data ties up the Rails process to stream a file, something
the front-end web server (Apache, Lighty, whatever) is FAR better suited
to do. Let me repeat that: using send_data means that process (Mongrel,
FCGI) cannot accept another rails request until you’re done streaming
the file.

You can offload sending the file to front-end server using X-Sendfile
headers. Google for your server’s specific implementation of x-sendfile,
and here’s the Rails plugin to enable it:

http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/

==
Will G.

The x-sendfile seems a good solution. In the case of the original
poster, he will have to save the data in a temp file and then x-send it.

/AITOR

Thanks everybody for yours replies.

he will have to save the data in a temp file and then x-send it.

Can you give me more hints about using x-sendfile in a radius tag?
How can I save the data, that comes from a database query, in a temp
file?

Greatings
Enzo