Hi- I''m trying to create a file upload script using RoR but I am getting "You have a nil object when you didn''t expect it!" and I think this is caused by the fact that the no form has been submitted. Is that right? Here''s the form: <% form_for :dump, :url => { :controller => "mycontroller", :action=> "csv_reader" }, :html => { :multipart => true } do |f| -%> <table> <tr> <label for="file"> <td><b><i>Select a CSV File: </i></b></td> </label> <td><%= file_field_tag ''file'' %></td> </tr> <tr> <td colspan=''2''><%= submit_tag "Submit" %></td> </tr> </table> <% end %> Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi- I''m trying to create a file upload script using RoR but I am getting "You have a nil object when you didn''t expect it!" and I think this is caused by the fact that the no form has been submitted. Is that right? Here''s the form: <% form_for :dump, :url => { :controller => "mycontroller", :action=> "csv_reader" }, :html => { :multipart => true } do |f| -%> <table> <tr> <label for="file"> <td><b><i>Select a CSV File: </i></b></td> </label> <td><%= file_field_tag ''file'' %></td> </tr> <tr> <td colspan=''2''><%= submit_tag "Submit" %></td> </tr> </table> <% end %> Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Not sure why that posted twice.... Anyhow, here''s how I call it in the controller: @file = CSV::Reader.parse(params[:dump][:file]) On Apr 2, 3:23 pm, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi- > > I''m trying to create a file upload script using RoR but I am getting > "You have a nil object when you didn''t expect it!" and I think this is > caused by the fact that the no form has been submitted. Is that > right? > > Here''s the form: > > <% form_for :dump, :url => { :controller => "mycontroller", :action=> > "csv_reader" }, :html => { :multipart => true } do |f| -%> > <table> > <tr> > <label for="file"> > <td><b><i>Select a CSV File: </i></b></td> > </label> > <td><%= file_field_tag ''file'' %></td> > </tr> > <tr> > <td colspan=''2''><%= submit_tag "Submit" %></td> > </tr> > </table> > <% end %> > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 2 Apr 2008, at 16:23, pete wrote:> > Hi- > > I''m trying to create a file upload script using RoR but I am getting > "You have a nil object when you didn''t expect it!" and I think this is > caused by the fact that the no form has been submitted. Is that > right? >Maybe, maybe not. The error message should tell you what line the error occurred on, then you need to go and look at that line of code and work out what''s wrong. Also look at the params hash being submitted. Fred> Here''s the form: > > <% form_for :dump, :url => { :controller => "mycontroller", :action=> > "csv_reader" }, :html => { :multipart => true } do |f| -%> > <table> > <tr> > <label for="file"> > <td><b><i>Select a CSV File: </i></b></td> > </label> > <td><%= file_field_tag ''file'' %></td> > </tr> > <tr> > <td colspan=''2''><%= submit_tag "Submit" %></td> > </tr> > </table> > <% end %> > > Thanks! > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s definitely an empty params hash. It fails on the line I posted below: @file = CSV::Reader.parse(params[:dump][:file]) How can I figure out what exactly is being passed? On Apr 2, 3:42 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Apr 2008, at 16:23, pete wrote: > > > > > Hi- > > > I''m trying to create a file upload script using RoR but I am getting > > "You have a nil object when you didn''t expect it!" and I think this is > > caused by the fact that the no form has been submitted. Is that > > right? > > Maybe, maybe not. The error message should tell you what line the > error occurred on, then you need to go and look at that line of code > and work out what''s wrong. Also look at the params hash being submitted. > > Fred > > > Here''s the form: > > > <% form_for :dump, :url => { :controller => "mycontroller", :action=> > > "csv_reader" }, :html => { :multipart => true } do |f| -%> > > <table> > > <tr> > > <label for="file"> > > <td><b><i>Select a CSV File: </i></b></td> > > </label> > > <td><%= file_field_tag ''file'' %></td> > > </tr> > > <tr> > > <td colspan=''2''><%= submit_tag "Submit" %></td> > > </tr> > > </table> > > <% end %> > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s because you have the file_field_tag ''file'' line if you want it to be inside dump, you need to do this: f.file_field_tag ''file'' as it stands, you will find the file by using params[:file] only. Julian. Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO (#2) OUT NOW! http://sensei.zenunit.com/ On 03/04/2008, at 2:46 AM, pete wrote:> > It''s definitely an empty params hash. It fails on the line I posted > below: > @file = CSV::Reader.parse(params[:dump][:file]) > > How can I figure out what exactly is being passed? > > On Apr 2, 3:42 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 2 Apr 2008, at 16:23, pete wrote: >> >> >> >>> Hi- >> >>> I''m trying to create a file upload script using RoR but I am getting >>> "You have a nil object when you didn''t expect it!" and I think >>> this is >>> caused by the fact that the no form has been submitted. Is that >>> right? >> >> Maybe, maybe not. The error message should tell you what line the >> error occurred on, then you need to go and look at that line of code >> and work out what''s wrong. Also look at the params hash being >> submitted. >> >> Fred >> >>> Here''s the form: >> >>> <% form_for :dump, :url => { :controller => >>> "mycontroller", :action=> >>> "csv_reader" }, :html => { :multipart => true } do |f| -%> >>> <table> >>> <tr> >>> <label for="file"> >>> <td><b><i>Select a CSV File: </i></b></td> >>> </label> >>> <td><%= file_field_tag ''file'' %></td> >>> </tr> >>> <tr> >>> <td colspan=''2''><%= submit_tag "Submit" %></td> >>> </tr> >>> </table> >>> <% end %> >> >>> Thanks! > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok, this isn''t working at all. I have tried just about everything and it seems like it should be so simple. I am constantly getting: NoMethodError in MyController#csv_reader You have a nil object when you didn''t expect it! The file shouldn''t be there until the submit button is selected so why is it even looking for it? On Apr 3, 8:34 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> It''s because you have the file_field_tag ''file'' line > > if you want it to be inside dump, you need to do this: > > f.file_field_tag ''file'' > > as it stands, you will find the file by using params[:file] only. > > Julian. > > Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO > (#2) OUT NOW!http://sensei.zenunit.com/ > > On 03/04/2008, at 2:46 AM, pete wrote: > > > > > It''s definitely an empty params hash. It fails on the line I posted > > below: > > @file = CSV::Reader.parse(params[:dump][:file]) > > > How can I figure out what exactly is being passed? > > > On Apr 2, 3:42 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 2 Apr 2008, at 16:23, pete wrote: > > >>> Hi- > > >>> I''m trying to create a file upload script using RoR but I am getting > >>> "You have a nil object when you didn''t expect it!" and I think > >>> this is > >>> caused by the fact that the no form has been submitted. Is that > >>> right? > > >> Maybe, maybe not. The error message should tell you what line the > >> error occurred on, then you need to go and look at that line of code > >> and work out what''s wrong. Also look at the params hash being > >> submitted. > > >> Fred > > >>> Here''s the form: > > >>> <% form_for :dump, :url => { :controller => > >>> "mycontroller", :action=> > >>> "csv_reader" }, :html => { :multipart => true } do |f| -%> > >>> <table> > >>> <tr> > >>> <label for="file"> > >>> <td><b><i>Select a CSV File: </i></b></td> > >>> </label> > >>> <td><%= file_field_tag ''file'' %></td> > >>> </tr> > >>> <tr> > >>> <td colspan=''2''><%= submit_tag "Submit" %></td> > >>> </tr> > >>> </table> > >>> <% end %> > > >>> Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
In case anyone has this same issue... You can use this to ignore the file, before submission (controller): unless params[:file].nil? And this is the correct code for the view: <% form_tag({:action=> "parse_csv"}, {:multipart => true}) do %> <table> <tr> <label for="dump_file"> <td><b><i>Select a CSV File: </i></b></td> </label> <td><%= file_field_tag ''file'' %></td> </tr> <tr> <td colspan=''2''><%= submit_tag "Submit" %></td> </tr> </table> <% end %> Note that the file is referenced as: params[:file] On Apr 3, 4:00 pm, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, this isn''t working at all. I have tried just about everything and > it seems like it should be so simple. > > I am constantly getting: > NoMethodError in MyController#csv_reader > > You have a nil object when you didn''t expect it! > > The file shouldn''t be there until the submit button is selected so why > is it even looking for it? > > On Apr 3, 8:34 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > > > It''s because you have the file_field_tag ''file'' line > > > if you want it to be inside dump, you need to do this: > > > f.file_field_tag ''file'' > > > as it stands, you will find the file by using params[:file] only. > > > Julian. > > > Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO > > (#2) OUT NOW!http://sensei.zenunit.com/ > > > On 03/04/2008, at 2:46 AM, pete wrote: > > > > It''s definitely an empty params hash. It fails on the line I posted > > > below: > > > @file = CSV::Reader.parse(params[:dump][:file]) > > > > How can I figure out what exactly is being passed? > > > > On Apr 2, 3:42 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> On 2 Apr 2008, at 16:23, pete wrote: > > > >>> Hi- > > > >>> I''m trying to create a file upload script using RoR but I am getting > > >>> "You have a nil object when you didn''t expect it!" and I think > > >>> this is > > >>> caused by the fact that the no form has been submitted. Is that > > >>> right? > > > >> Maybe, maybe not. The error message should tell you what line the > > >> error occurred on, then you need to go and look at that line of code > > >> and work out what''s wrong. Also look at the params hash being > > >> submitted. > > > >> Fred > > > >>> Here''s the form: > > > >>> <% form_for :dump, :url => { :controller => > > >>> "mycontroller", :action=> > > >>> "csv_reader" }, :html => { :multipart => true } do |f| -%> > > >>> <table> > > >>> <tr> > > >>> <label for="file"> > > >>> <td><b><i>Select a CSV File: </i></b></td> > > >>> </label> > > >>> <td><%= file_field_tag ''file'' %></td> > > >>> </tr> > > >>> <tr> > > >>> <td colspan=''2''><%= submit_tag "Submit" %></td> > > >>> </tr> > > >>> </table> > > >>> <% end %> > > > >>> Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pete, You do know this is in the api for form_tag, don''t you? Julian. Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3 OUT APRIL 6 http://sensei.zenunit.com/ On 04/04/2008, at 7:08 AM, pete wrote:> > In case anyone has this same issue... > > You can use this to ignore the file, before submission (controller): > unless params[:file].nil? > > And this is the correct code for the view: > <% form_tag({:action=> "parse_csv"}, {:multipart => true}) do %> > <table> > <tr> > <label for="dump_file"> > <td><b><i>Select a CSV File: </i></b></td> > </label> > <td><%= file_field_tag ''file'' %></td> > </tr> > <tr> > <td colspan=''2''><%= submit_tag "Submit" %></td> > </tr> > </table> > <% end %> > > Note that the file is referenced as: params[:file] > > > On Apr 3, 4:00 pm, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Ok, this isn''t working at all. I have tried just about everything >> and >> it seems like it should be so simple. >> >> I am constantly getting: >> NoMethodError in MyController#csv_reader >> >> You have a nil object when you didn''t expect it! >> >> The file shouldn''t be there until the submit button is selected so >> why >> is it even looking for it? >> >> On Apr 3, 8:34 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: >> >>> It''s because you have the file_field_tag ''file'' line >> >>> if you want it to be inside dump, you need to do this: >> >>> f.file_field_tag ''file'' >> >>> as it stands, you will find the file by using params[:file] only. >> >>> Julian. >> >>> Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW >>> VIDEO >>> (#2) OUT NOW!http://sensei.zenunit.com/ >> >>> On 03/04/2008, at 2:46 AM, pete wrote: >> >>>> It''s definitely an empty params hash. It fails on the line I >>>> posted >>>> below: >>>> @file = CSV::Reader.parse(params[:dump][:file]) >> >>>> How can I figure out what exactly is being passed? >> >>>> On Apr 2, 3:42 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>> wrote: >>>>> On 2 Apr 2008, at 16:23, pete wrote: >> >>>>>> Hi- >> >>>>>> I''m trying to create a file upload script using RoR but I am >>>>>> getting >>>>>> "You have a nil object when you didn''t expect it!" and I think >>>>>> this is >>>>>> caused by the fact that the no form has been submitted. Is that >>>>>> right? >> >>>>> Maybe, maybe not. The error message should tell you what line the >>>>> error occurred on, then you need to go and look at that line of >>>>> code >>>>> and work out what''s wrong. Also look at the params hash being >>>>> submitted. >> >>>>> Fred >> >>>>>> Here''s the form: >> >>>>>> <% form_for :dump, :url => { :controller => >>>>>> "mycontroller", :action=> >>>>>> "csv_reader" }, :html => { :multipart => true } do |f| -%> >>>>>> <table> >>>>>> <tr> >>>>>> <label for="file"> >>>>>> <td><b><i>Select a CSV File: </i></b></td> >>>>>> </label> >>>>>> <td><%= file_field_tag ''file'' %></td> >>>>>> </tr> >>>>>> <tr> >>>>>> <td colspan=''2''><%= submit_tag "Submit" %></td> >>>>>> </tr> >>>>>> </table> >>>>>> <% end %> >> >>>>>> Thanks! > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It didn''t seem that clear to me in the API so I added another example here should anyone else feel the same. Thanks Julian. On Apr 3, 10:28 pm, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> Pete, > > You do know this is in the api for form_tag, don''t you? > > Julian. > > Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3 > OUT APRIL 6http://sensei.zenunit.com/ > > On 04/04/2008, at 7:08 AM, pete wrote: > > > > > In case anyone has this same issue... > > > You can use this to ignore the file, before submission (controller): > > unless params[:file].nil? > > > And this is the correct code for the view: > > <% form_tag({:action=> "parse_csv"}, {:multipart => true}) do %> > > <table> > > <tr> > > <label for="dump_file"> > > <td><b><i>Select a CSV File: </i></b></td> > > </label> > > <td><%= file_field_tag ''file'' %></td> > > </tr> > > <tr> > > <td colspan=''2''><%= submit_tag "Submit" %></td> > > </tr> > > </table> > > <% end %> > > > Note that the file is referenced as: params[:file] > > > On Apr 3, 4:00 pm, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Ok, this isn''t working at all. I have tried just about everything > >> and > >> it seems like it should be so simple. > > >> I am constantly getting: > >> NoMethodError in MyController#csv_reader > > >> You have a nil object when you didn''t expect it! > > >> The file shouldn''t be there until the submit button is selected so > >> why > >> is it even looking for it? > > >> On Apr 3, 8:34 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > > >>> It''s because you have the file_field_tag ''file'' line > > >>> if you want it to be inside dump, you need to do this: > > >>> f.file_field_tag ''file'' > > >>> as it stands, you will find the file by using params[:file] only. > > >>> Julian. > > >>> Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW > >>> VIDEO > >>> (#2) OUT NOW!http://sensei.zenunit.com/ > > >>> On 03/04/2008, at 2:46 AM, pete wrote: > > >>>> It''s definitely an empty params hash. It fails on the line I > >>>> posted > >>>> below: > >>>> @file = CSV::Reader.parse(params[:dump][:file]) > > >>>> How can I figure out what exactly is being passed? > > >>>> On Apr 2, 3:42 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>>> wrote: > >>>>> On 2 Apr 2008, at 16:23, pete wrote: > > >>>>>> Hi- > > >>>>>> I''m trying to create a file upload script using RoR but I am > >>>>>> getting > >>>>>> "You have a nil object when you didn''t expect it!" and I think > >>>>>> this is > >>>>>> caused by the fact that the no form has been submitted. Is that > >>>>>> right? > > >>>>> Maybe, maybe not. The error message should tell you what line the > >>>>> error occurred on, then you need to go and look at that line of > >>>>> code > >>>>> and work out what''s wrong. Also look at the params hash being > >>>>> submitted. > > >>>>> Fred > > >>>>>> Here''s the form: > > >>>>>> <% form_for :dump, :url => { :controller => > >>>>>> "mycontroller", :action=> > >>>>>> "csv_reader" }, :html => { :multipart => true } do |f| -%> > >>>>>> <table> > >>>>>> <tr> > >>>>>> <label for="file"> > >>>>>> <td><b><i>Select a CSV File: </i></b></td> > >>>>>> </label> > >>>>>> <td><%= file_field_tag ''file'' %></td> > >>>>>> </tr> > >>>>>> <tr> > >>>>>> <td colspan=''2''><%= submit_tag "Submit" %></td> > >>>>>> </tr> > >>>>>> </table> > >>>>>> <% end %> > > >>>>>> Thanks!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---