# Send\_file errors out with nil.update

**URL:** <https://www.ruby-forum.com/t/send-file-errors-out-with-nil-update/181649>\
**Category:** Rails\
**Created:** [January 15, 2010, 7:15am UTC](https://www.ruby-forum.com/t/send-file-errors-out-with-nil-update/181649 "2010-01-15T07:15:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [January 15, 2010, 7:15am UTC](https://www.ruby-forum.com/t/send-file-errors-out-with-nil-update/181649/1 "2010-01-15T07:15:06Z")

</div>

Hey everyone,

I’ve got a basic setup via an apache2 server, virtualhost ect. At the  
moment I’m just trying to use the send\_file function of rails  
(actionpack I believe?) but it continues to error out. Here is the  
breakdown:

#Controller#

class Misc \< ApplicationController

def stuff  
send\_file("#{RAILS\_ROOT}/downloads/test.txt")  
end

end

#View#

\<% a = Misc.new %\>

\<%= a.stuff %\>

And this is the error I’ve been getting:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.update

Extracted source (around line #3):

2: \<% a = Misc.new %\>  
3:

\<%= a.stuff %\>

Trace yields the following:

vendor/rails/actionpack/lib/action\_controller/streaming.rb:139:in  
`send_file_headers!' vendor/rails/actionpack/lib/action_controller/streaming.rb:72:in`send\_file’  
app/controllers/home\_controller.rb:16:in `stuff' app/views/home/index.html.erb:3:in`\_run\_erb\_47app47views47home47index46html46erb’

Any suggestions?

_one thing i will note, dunno if it matters, is that rails 2.3.5 wouldnt  
install - kept complaining about rack 1.0.0 runtime, so instead i  
installed all the packages and dependencies separately via apt-get  
install actionpack -v=2.3.4  
ect ect, using 2.3.4 instead_

Thanks!

-Regards  
Mac

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [January 15, 2010, 11:12am UTC](https://www.ruby-forum.com/t/send-file-errors-out-with-nil-update/181649/2 "2010-01-15T11:12:09Z")

</div>

On Jan 15, 6:15Â am, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Â def stuff  
> Â Â send\_file(“#{RAILS\_ROOT}/downloads/test.txt”)  
> Â end
> 
> end
> 
> #View#
> 
> \<% a = Misc.new %\>
> 
> \<%= a.stuff %\>

This looks a little weird - from inside the view you’re trying to  
create a new instance of a controller ? This is probably failing  
because you haven’t initialized the controller properly. Why not call  
send\_file from the appropriate controller action ?

Fred

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [January 15, 2010, 4:11pm UTC](https://www.ruby-forum.com/t/send-file-errors-out-with-nil-update/181649/3 "2010-01-15T16:11:36Z")

</div>

Frederick C. wrote:

> On Jan 15, 6:15Â am, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Â def stuff  
> > Â Â send\_file(“#{RAILS\_ROOT}/downloads/test.txt”)  
> > Â end
> > 
> > end
> > 
> > #View#
> > 
> > \<% a = Misc.new %\>
> > 
> > \<%= a.stuff %\>
> 
> This looks a little weird - from inside the view you’re trying to  
> create a new instance of a controller ? This is probably failing  
> because you haven’t initialized the controller properly. Why not call  
> send\_file from the appropriate controller action ?
> 
> Fred

o\_O worked without a hitch… why would this be? As you suggested I  
threw it back in HomeController (via script/generate controller home  
index) under def index and walaa! But why can I not define a new class  
to separate objects in the same controller?

Regards,

- Mac

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [January 15, 2010, 4:20pm UTC](https://www.ruby-forum.com/t/send-file-errors-out-with-nil-update/181649/4 "2010-01-15T16:20:04Z")

</div>

On Jan 15, 3:11Â pm, Michael L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Frederick C. wrote:
> 
> o\_O worked without a hitch… why would this be? As you suggested I  
> threw it back in HomeController (via script/generate controller home  
> index) under def index and walaa!

Because that’s just how it’s supposed to work

> But why can I not define a new class  
> to separate objects in the same controller?

I’m not entirely sure what you’re trying to achieve. You probably  
could create a new controller, but you’d need to set it up so that it  
thought it was responding to the same http request etc (ie the work  
that rails does when a new request comes in). I’m still not sure what  
you’d achieve by that though.

Fred
