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? When I do this session[:people_search][:full_name] = params[:full_name] session[:people_search][:email] = params[:email] session[:people_search][:postal_code] = params[:postal_code] Everything works as I want it to. But when i do this session[:people_search].merge!(params) or session[:people_search] = session[:people_search].merge(params) or session[:people_search] = params it does not work. 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. Thanks, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > 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. *sigh*> > Thanks, > Phillip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 28, 12:17 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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? ///ark --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 28, 2007, at 3:43 PM, Mark Wilden wrote:> > On Dec 28, 12:17 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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. Why? Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 28 Dec 2007, at 22:45, Phillip Koebbe wrote:> > > On Dec 28, 2007, at 3:43 PM, Mark Wilden wrote: > >> >> On Dec 28, 12:17 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> 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. >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. Fred> Why? > > Phillip > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 28, 2:45 pm, Phillip Koebbe <phillipkoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---