Can't add hash key during iteration

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.

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

Modifying 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

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.

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

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