Rails 3.0.5 Code that runs fine in 1.8.7 is balking in 1.9.2 I guess 1.9 has fundamentally changed something like this (assuming keys are symbols): my_hash.each do |key, value| my_hash[key.to_s] = value end to now require something like this: my_hash.dup.each do |key, value| my_hash[key.to_s] = my_hash.delete(key) end However, I am getting the error at this simple line (the first line in a little method to stuff params with some values): params[:search_form] ||= {} There is no iteration. Even changing it to this didn''t help. Didn''t really think it would, but tried it anyway. if !params.has_key?(:search_form) params.store(:search_form, {}) end Anyone know what the deal is here? Thanks. -- 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 Mar 21, 8:19 pm, Greg Willits <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Rails 3.0.5 > Code that runs fine in 1.8.7 is balking in 1.9.2 > > I guess 1.9 has fundamentally changed something like this (assuming keys > are symbols): > > my_hash.each do |key, value| > my_hash[key.to_s] = value > endModifying a collection while enumerating over it has always been a dangerous way to live (do you want stringify_keys (from Active Support) ?)> > to now require something like this: > > my_hash.dup.each do |key, value| > my_hash[key.to_s] = my_hash.delete(key) > end > > However, I am getting the error at this simple line (the first line in a > little method to stuff params with some values): > > params[:search_form] ||= {} >What error? Fred> There is no iteration. > > Even changing it to this didn''t help. Didn''t really think it would, but > tried it anyway. > > if !params.has_key?(:search_form) > params.store(:search_form, {}) > end > > Anyone know what the deal is here? Thanks. > > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #988609:> What error?Sorry, now that I reread my post, it''s not very clear. I am getting the error "can''t add a new key into hash during iteration" reported for this line of code: params[:search_form] ||= {} which makes no sense at all. The iteration examples in my first post were just my way of explaining I understood the basic error msg and what it would normally relate to. However, the actual error msg is not tracing back to an iteration--just that simple line with params ||=. Experimenting a little more, it appears it matters _where_ I use that line of code. I''m not sure how to distill this down, so here''s the semi-detailed version... Two relevant files: a rails controller, and a module file stored in /lib which gets included in ApplicationController. #--------------------------------------- class MyController < ApplicationController include GwControllerExtras def admin sasc_initialize(...) # an abstraction for handling a bunch of UI interaction end private # called from within sasc_initialize() def submit_form_x end # called from within sasc_initialize() def prep_view_y update_sticky_search end end #--------------------------------------- # /lib/admin_ui_extras.rb module GwControllerExtras def update_sticky_search params[:search_form] ||= {} # <<<<< FAILS # more stuff end end OK, so the line that fails is the one shown just above. Now, if I move that line out of the update_sticky_search method and into the prep_view_y method just before the call to update_sticky_search, there is no error. Bizarre! There''s a couple other places where I can move it in the call chain that either crashes or doesn''t crash with the "can''t add a new key into hash during iteration" error. So, somehow, location matters. There''s something specific to 192 here, because update_sticky_search works fine in 186 and 187. I hope that''s clearer. -- gw -- 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.
> I am getting the error "can''t add a new key into hash during iteration" > reported for this line of code: > params[:search_form] ||= {}After much tinkering, I found a clean enough work around to live with it, but still no closer to understanding why the error was happening. -- gw -- 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 Mar 21, 9:38 pm, Greg Willits <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > OK, so the line that fails is the one shown just above. Now, if I move > that line out of the update_sticky_search method and into the > prep_view_y method just before the call to update_sticky_search, there > is no error. Bizarre! >So is update_sticky_search called from someplace that (among other things) is iterating over params? Fred> There''s a couple other places where I can move it in the call chain that > either crashes or doesn''t crash with the "can''t add a new key into hash > during iteration" error. So, somehow, location matters. > > There''s something specific to 192 here, because update_sticky_search > works fine in 186 and 187. > > I hope that''s clearer. > > -- gw > > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.