I have a search form that submits three parameters via an xhr
request. The three parameters are full_name, email, and postal_code.
In the controller action, I want to stuff those values into the
session so they can be accessed later to repopulate the search form.
I start by making sure there is a place in session
session[:people_search] = Hash.new if session[:people_search].nil?
In case you’re curious, I don’t mind the other keys that exist in
params. I’m just trying to find the easiest and most portable way to
get things out of params into session.
Can someone explain to me why the direct assignment of each
individual key works but none of the other methods do.
Can someone explain to me why the direct assignment of each
individual key works but none of the other methods do.
Five more minutes. I couldn’t have thought about it for five more
minutes!
params is a HashWithIndifferentAccess while my session
[:people_search] was just a plain old Hash. When I changed the
instantiation of session[:people_search] to
HashWithIndifferentAccess, it works.
params is a HashWithIndifferentAccess while my session
[:people_search] was just a plain old Hash. When I changed the
instantiation of session[:people_search] to
HashWithIndifferentAccess, it works.
Just for my education, would changing the keys from symbols to strings
also have worked?
params is a HashWithIndifferentAccess while my session
[:people_search] was just a plain old Hash. When I changed the
instantiation of session[:people_search] to
HashWithIndifferentAccess, it works.
Just for my education, would changing the keys from symbols to strings
also have worked?
Well, apparently for my education, too. Changing the keys from
symbols to strings does, in fact, work.
Just for my education, would changing the keys from symbols to
strings
also have worked?
Well, apparently for my education, too. Changing the keys from
symbols to strings does, in fact, work.
Because in the HashWithIndifferentAccess you get as params the keys
are, deep down on the inside, strings, so when you merged that into
your array you got a bunch of string keys but you were looking for
symbol keys.
Well, apparently for my education, too. Changing the keys from
symbols to strings does, in fact, work.
Why?
What Fred said.
When I saw a class called HashWithIndifferentAccess, I just had to
look into it. What a name! It’s like “I couldn’t care less whether you
access me or not, but if you do, it really doesn’t matter if it’s with
symbols or strings. It’s all the same to me. Yawn.”
///ark
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.