# Creating a tempfile that should be used by 2 controllers

**URL:** <https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866>\
**Category:** Rails\
**Created:** [May 23, 2007, 11:43am UTC](https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866 "2007-05-23T11:43:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fred\_o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e99b99/32.png) [@fred\_o](https://www.ruby-forum.com/u/fred_o)\
**Post date:** [May 23, 2007, 11:43am UTC](https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866/1 "2007-05-23T11:43:48Z")

</div>

Hi,

To summarize I have an application with two pages:

- one is a form and a controller is attached to it. Crontoller generates  
a file given the information entered in the form;
- the other is a download-page and also has its own controller…

In single-user mode I had no problem as I always used the same name for  
the file. Now, I want to go to multi-users mode. I was thinking of using  
tempfile but I can’t get the two controller to use the same tempfile…

Do you think it is possible to have two controllers using the same  
tempfile? Or may be my design is incorrect… any help welcome! Thanx

Regards,

Fred

---

<div class="post-metadata">

**Author:** ![fred\_o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e99b99/32.png) [@fred\_o](https://www.ruby-forum.com/u/fred_o)\
**Post date:** [May 23, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866/2 "2007-05-23T18:09:37Z")

</div>

Why do you think you need multiple controllers? A controller can have  
multiple actions, and actions have views associated with them. What  
you’ve described seems to be two actions. I don’t see a need for a  
second controller, and I also don’t see a need for a temp file. Why  
not send a file directly to the user as the response of an action.

- Mark.

---

<div class="post-metadata">

**Author:** ![fred\_o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e99b99/32.png) [@fred\_o](https://www.ruby-forum.com/u/fred_o)\
**Post date:** [May 23, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866/3 "2007-05-23T18:09:37Z")

</div>

Why do you think you need multiple controllers? A controller can have  
multiple actions, and actions have views associated with them. What  
you’ve described seems to be two actions. I don’t see a need for a  
second controller, and I also don’t see a need for a temp file. Why  
not send a file directly to the user as the response of an action.

---

<div class="post-metadata">

**Author:** ![fred\_o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e99b99/32.png) [@fred\_o](https://www.ruby-forum.com/u/fred_o)\
**Post date:** [May 23, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866/4 "2007-05-23T18:09:38Z")

</div>

Why do you think you need multiple controllers? A controller can have  
multiple actions, and actions have views associated with them. What  
you’ve described seems to be two actions. I don’t see a need for a  
second controller, and I also don’t see a need for a temp file. Why  
not send a file directly to the user as the response of an action.

- Mark.

---

<div class="post-metadata">

**Author:** ![fred\_o](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e99b99/32.png) [@fred\_o](https://www.ruby-forum.com/u/fred_o)\
**Post date:** [May 24, 2007, 9:23am UTC](https://www.ruby-forum.com/t/creating-a-tempfile-that-should-be-used-by-2-controllers/104866/5 "2007-05-24T09:23:08Z")

</div>

Mark T. wrote:

> Why do you think you need multiple controllers? A controller can have  
> multiple actions, and actions have views associated with them. What  
> you’ve described seems to be two actions. I don’t see a need for a  
> second controller, and I also don’t see a need for a temp file. Why  
> not send a file directly to the user as the response of an action.
> 
> - Mark.

I thougth needed 2 controllers cause of 2 different views… I didn’t  
think of sending file to finish in first controller. Wanted to offer  
downloading and emailing option in the second view but just realised  
could just add a field in the form to do that.

Thank you for the help.

Fred
