# Radius tag and send\_data method

**URL:** <https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384>\
**Category:** Radiant CMS\
**Created:** [November 6, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384 "2007-11-06T16:43:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![enzo\_ferro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@enzo\_ferro](https://www.ruby-forum.com/u/enzo_ferro)\
**Post date:** [November 6, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384/1 "2007-11-06T16:43:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![enzo\_ferro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@enzo\_ferro](https://www.ruby-forum.com/u/enzo_ferro)\
**Post date:** [November 6, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384/2 "2007-11-06T17:52:20Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![enzo\_ferro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@enzo\_ferro](https://www.ruby-forum.com/u/enzo_ferro)\
**Post date:** [November 6, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384/3 "2007-11-06T18:49:39Z")

</div>

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/](http://john.guen.in/past/2007/4/17/send_files_faster_with_xsendfile/)

==  
Will G.

---

<div class="post-metadata">

**Author:** ![enzo\_ferro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@enzo\_ferro](https://www.ruby-forum.com/u/enzo_ferro)\
**Post date:** [November 6, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384/4 "2007-11-06T19:28:20Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![enzo\_ferro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@enzo\_ferro](https://www.ruby-forum.com/u/enzo_ferro)\
**Post date:** [November 7, 2007, 10:47am UTC](https://www.ruby-forum.com/t/radius-tag-and-send-data-method/119384/5 "2007-11-07T10:47:08Z")

</div>

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
