I seem to have some cookies (semi-)working. Sometimes I get the following 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.[] Sometimes I don''t. My controller contains: def prefs cookies.delete :runs cookies.delete :failures @values = params[:prefs] cookies[:runs] = { :value => @values[:runs]} cookies[:failures] = { :value => @values[:failures]} end My view contains: <%= form_tag :action => "prefs" %> Number of runs to display: <%= text_field :prefs, :runs %><br /> Number of run failures to display: <%= text_field :prefs, :failures %> <%= submit_tag ''Save Preferences'' %> The error is being thrown up on the two lines beginning cookies[:runs] and cookies[:failures] in my controller. Anyone any ideas why? -- 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-/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 -~----------~----~----~----~------~----~------~--~---
> Sometimes I don''t. > > My controller contains: > > def prefs > cookies.delete :runs > cookies.delete :failures > @values = params[:prefs] > cookies[:runs] = { :value => @values[:runs]} > cookies[:failures] = { :value => @values[:failures]} > endfirst off, from what the error says, You might have expected an instance of Array. and if you say it errors on the below lines: @values = params[:prefs] cookies[:runs] = { :value => @values[:runs]} cookies[:failures] = { :value => @values[:failures]} the problem is that @values should be an array, but it is not (i.e, the params[:prefs] is nil) - check to see if it is being passed correctly. second off, not closley related to the problem, but for some reason it''s helped me before with cookies - add an expires opt as well: :expires => Time.now + 10.days the cookie can expire out, when you don''t want it too.. it''s better to add an expire opt as well as the value (you can add a Time.now + 10.years if you don''t really want it expiring ..) hth -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld wrote:>> Sometimes I don''t. >> >> My controller contains: >> >> def prefs >> cookies.delete :runs >> cookies.delete :failures >> @values = params[:prefs] >> cookies[:runs] = { :value => @values[:runs]} >> cookies[:failures] = { :value => @values[:failures]} >> end > > first off, from what the error says, You might have expected an instance > of Array. and if you say it errors on the below lines: > > @values = params[:prefs] > cookies[:runs] = { :value => @values[:runs]} > cookies[:failures] = { :value => @values[:failures]} > > the problem is that @values should be an array, but it is not (i.e, the > params[:prefs] is nil) - check to see if it is being passed correctly. > > > second off, not closley related to the problem, but for some reason it''s > helped me before with cookies - > add an expires opt as well: > > :expires => Time.now + 10.days > > the cookie can expire out, when you don''t want it too.. it''s better to > add an expire opt as well as the value (you can add a Time.now + > 10.years if you don''t really want it expiring ..) > > hthWell it seems to be passed correctly, as it works the first time and then fails any subsequent times! I added the ''expires'' option shortly after my post so i''m sure it''s not this causing the problem. Anyone any more ideas? -- 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-/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 -~----------~----~----~----~------~----~------~--~---