# Render file

**URL:** <https://www.ruby-forum.com/t/render-file/103135>\
**Category:** Rails\
**Created:** [May 2, 2007, 6:36am UTC](https://www.ruby-forum.com/t/render-file/103135 "2007-05-02T06:36:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [May 2, 2007, 6:36am UTC](https://www.ruby-forum.com/t/render-file/103135/1 "2007-05-02T06:36:32Z")

</div>

Hi,  
I want to send file in the response,  
I found it’s possible with render method:  
def get\_file  
render :file =\> path, :content\_type =\> “application/x-unknown”  
end.

But there is one problem,  
the default name of that file in system dialog is the method name.

Is it possible to set default file name?

Greets.

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [May 3, 2007, 10:08am UTC](https://www.ruby-forum.com/t/render-file/103135/2 "2007-05-03T10:08:36Z")

</div>

Zirael wrote:

> Hi,  
> I want to send file in the response,  
> I found it’s possible with render method:  
> def get\_file  
> render :file =\> path, :content\_type =\> “application/x-unknown”  
> end.
> 
> But there is one problem,  
> the default name of that file in system dialog is the method name.
> 
> Is it possible to set default file name?
> 
> Greets.

…ever look into the FileUtils / File classes?

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [May 3, 2007, 10:42am UTC](https://www.ruby-forum.com/t/render-file/103135/3 "2007-05-03T10:42:26Z")

</div>

Zirael wrote:

> Is it possible to set default file name?
> 
> Greets.

The file name is the last path step of the url… so put a complete url  
for that download in routes and map it to your get\_file action…  
something like:

map.connect ‘/something/myfilename.xxx’,  
:controller =\> ‘mycontroller’, :action =\> ‘get\_file’

Note that you may also need to set the Content-Disposition header to  
Attachment to get a file save dialog on some browsers… depending on  
the content-type I suppose.

b
