I saw a post for a select tag, in the options_for_select([["value 1", "1"], ["value 2", "2"], "3", "4"],["1", "3"]) works fine. If I do @test_select = [["value 1", "1"],["value 2", "2"], "3", "4"], ["1", "3"] in the controller I try to do options_for_select(@test_select) in the place I get a NIL value. Any reason why the array is not getting to the view?? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jul-31 08:07 UTC
Re: use an array in a controller to populate a select box
the array should consist of two element arrays, one element is the key, the other the value. Don''t see, what you want to do with this strange mix of values and arrays here. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-31 12:45 UTC
Re: use an array in a controller to populate a select box
On 30 Jul 2008, at 19:29, Me wrote:> > I saw a post for a select tag, in the options_for_select([["value 1", > "1"], ["value 2", "2"], "3", "4"],["1", "3"]) works fine. > > If I do @test_select = [["value 1", "1"],["value 2", "2"], "3", "4"], > ["1", "3"] in the controller > > I try to do options_for_select(@test_select) in the place I get a NIL > value. Any reason why the array is not getting to the view?? >You''re probably not quite doing what you think you are. Post some code. As a random shot in the dark, if you are calling render explicitly then you must set @test_select before you do this. 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-/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 the controller I have @test_select = [[''New Install'',''1''],[''NIU LOOP'',''2''],[''CSU LOOP'',''3''],[''NIU_CSU LOOP'',''4''],[''Maintenance'',''5'']] In the view I have <%= select(''test_method'', ''id'', @test_select, {:prompt => ''Select Test Method'' } )%> Why is it telling me there is a NIL value where the variable @test_select is? I am not sure how to get it to give me a select list. On Jul 31, 7:45 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 Jul 2008, at 19:29, Me wrote: > > > > > I saw a post for a select tag, in the options_for_select([["value 1", > > "1"], ["value 2", "2"], "3", "4"],["1", "3"]) works fine. > > > If I do @test_select = [["value 1", "1"],["value 2", "2"], "3", "4"], > > ["1", "3"] in the controller > > > I try to do options_for_select(@test_select) in the place I get a NIL > > value. Any reason why the array is not getting to the view?? > > You''re probably not quite doing what you think you are. Post some code. > > As a random shot in the dark, if you are calling render explicitly > then you must set @test_select before you do this. > > 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-/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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jul-31 17:28 UTC
Re: use an array in a controller to populate a select box
On 31 Jul 2008, at 18:22, Me wrote:> > This is the View error: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.inject >stack trace sure would be useful... What''s in the controller ? Fred> Extracted source (around line #13): > > 10: > 11: <p> > 12: <div id="time1" style="display: inline">T-1 #1 <%> text_field :circuit1, :name, :size => ''15'', :value => "Circuit > ID", :onfocus => "if (this.value == ''Circuit ID'') {this.value > '''';}",:onblur => "if (this.value == '''') {this.value = ''Circuit > ID'';}" - > %> > 13: <%= select(''test_method'', ''id'', @test_select, {:prompt => > ''Select Test Method'' } )%> > 14: <%= text_field :time1, :time, :size => ''5'', :value => > "Time", :onfocus => "if (this.value == ''Time'') {this.value > '''';}",:onblur => "if (this.value == '''') {this.value = ''Time'';}" -%> > 15: <%= submit_to_remote ''commit1'', "Test Circuit",:onclick => "new > Element.show(''save'')", > 16: :url => { :action => ''diagnose_circuit'' }, > > RAILS_ROOT: F:/BACKUP/Backup/Web_apps_svn_working/CircuitDiagnosis > Application Trace | Framework Trace | Full Trace > > On Jul 31, 12:16 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 31 Jul 2008, at 18:14, Me wrote: >> >> >> >>> In the controller I have @test_select = [[''New Install'',''1''],[''NIU >>> LOOP'',''2''],[''CSU LOOP'',''3''],[''NIU_CSU LOOP'',''4''], >>> [''Maintenance'',''5'']] >> >>> In the view I have <%= select(''test_method'', ''id'', @test_select, >>> {:prompt => ''Select Test Method'' } )%> >> >>> Why is it telling me there is a NIL value where the variable >>> @test_select is? >> >> post all your code, not just the snippets. eg what line is raising an >> exception and what is the stack trace? >> >> Fred >> >> >> >>> I am not sure how to get it to give me a select list. >> >>> On Jul 31, 7:45 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> wrote: >>>> On 30 Jul 2008, at 19:29, Me wrote: >> >>>>> I saw a post for a select tag, in the options_for_select([["value >>>>> 1", >>>>> "1"], ["value 2", "2"], "3", "4"],["1", "3"]) works fine. >> >>>>> If I do @test_select = [["value 1", "1"],["value 2", "2"], "3", >>>>> "4"], >>>>> ["1", "3"] in the controller >> >>>>> I try to do options_for_select(@test_select) in the place I get a >>>>> NIL >>>>> value. Any reason why the array is not getting to the view?? >> >>>> You''re probably not quite doing what you think you are. Post some >>>> code. >> >>>> As a random shot in the dark, if you are calling render explicitly >>>> then you must set @test_select before you do this. >> >>>> 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-/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 -~----------~----~----~----~------~----~------~--~---
Doh. Fixed it. Had the stinking Instance var in the wrong place in the controller. On Jul 31, 12:28 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 31 Jul 2008, at 18:22, Me wrote: > > > > > This is the View error: > > > You have a nil object when you didn''t expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.inject > > stack trace sure would be useful... > What''s in the controller ? > > Fred > > > Extracted source (around line #13): > > > 10: > > 11: <p> > > 12: <div id="time1" style="display: inline">T-1 #1 <%> > text_field :circuit1, :name, :size => ''15'', :value => "Circuit > > ID", :onfocus => "if (this.value == ''Circuit ID'') {this.value > > '''';}",:onblur => "if (this.value == '''') {this.value = ''Circuit > > ID'';}" - > > %> > > 13: <%= select(''test_method'', ''id'', @test_select, {:prompt => > > ''Select Test Method'' } )%> > > 14: <%= text_field :time1, :time, :size => ''5'', :value => > > "Time", :onfocus => "if (this.value == ''Time'') {this.value > > '''';}",:onblur => "if (this.value == '''') {this.value = ''Time'';}" -%> > > 15: <%= submit_to_remote ''commit1'', "Test Circuit",:onclick => "new > > Element.show(''save'')", > > 16: :url => { :action => ''diagnose_circuit'' }, > > > RAILS_ROOT: F:/BACKUP/Backup/Web_apps_svn_working/CircuitDiagnosis > > Application Trace | Framework Trace | Full Trace > > > On Jul 31, 12:16 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 31 Jul 2008, at 18:14, Me wrote: > > >>> In the controller I have @test_select = [[''New Install'',''1''],[''NIU > >>> LOOP'',''2''],[''CSU LOOP'',''3''],[''NIU_CSU LOOP'',''4''], > >>> [''Maintenance'',''5'']] > > >>> In the view I have <%= select(''test_method'', ''id'', @test_select, > >>> {:prompt => ''Select Test Method'' } )%> > > >>> Why is it telling me there is a NIL value where the variable > >>> @test_select is? > > >> post all your code, not just the snippets. eg what line is raising an > >> exception and what is the stack trace? > > >> Fred > > >>> I am not sure how to get it to give me a select list. > > >>> On Jul 31, 7:45 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >>> wrote: > >>>> On 30 Jul 2008, at 19:29, Me wrote: > > >>>>> I saw a post for a select tag, in the options_for_select([["value > >>>>> 1", > >>>>> "1"], ["value 2", "2"], "3", "4"],["1", "3"]) works fine. > > >>>>> If I do @test_select = [["value 1", "1"],["value 2", "2"], "3", > >>>>> "4"], > >>>>> ["1", "3"] in the controller > > >>>>> I try to do options_for_select(@test_select) in the place I get a > >>>>> NIL > >>>>> value. Any reason why the array is not getting to the view?? > > >>>> You''re probably not quite doing what you think you are. Post some > >>>> code. > > >>>> As a random shot in the dark, if you are calling render explicitly > >>>> then you must set @test_select before you do this. > > >>>> 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-/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 -~----------~----~----~----~------~----~------~--~---