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 %> <p><%= a.stuff %></p> 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: <p><%= a.stuff %></p> 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 15, 6:15 am, Michael Linfield <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 %> > <p><%= a.stuff %></p>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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jan 15, 6:15 am, Michael Linfield <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> def stuff >> send_file("#{RAILS_ROOT}/downloads/test.txt") >> end >> >> end >> >> #View# >> >> <% a = Misc.new %> >> <p><%= a.stuff %></p> > > 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 ? > > Fredo_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 -- Posted via http://www.ruby-forum.com/. --0022158df84f851f6d047d356b35 Content-Type: text/plain; charset=ISO-8859-1 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. --0022158df84f851f6d047d356b35--
On Jan 15, 3:11 pm, Michael Linfield <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.