Hi all, My app is going to count sth based on poll id in the url. The url looks like: http://address.com?id=dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7&some_other_parameters In a controller, I''ve created a hash where the keys are the ids: @codes = { ''dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7'' => {:partner_id => 0, :partner_name => ''sth'', :page_number => 1}, ... } Then i do: poll_id = ''"'' + params[''id''] + ''"'' The problem is, @codes[poll_id] returns nil. Otherwise, @codes["dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7"] works ok. What am I doing wrong if the keys are the same and explicite string works while variable doesn''t? Can you explain me that and write how to solve that problem? Thanks in advance, greetz -- K.O.N.L.I.N. konlin@post.pl Kinetic Organism Normally for Logical Infiltration and Nullification, "Day after day, love turns grey Like the skin of a dying man"
Hi -- On Sun, 19 Mar 2006, Konlin wrote:> Hi all, > > My app is going to count sth based on poll id in the url. The url > looks like: > http://address.com?id=dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7&some_other_parameters > > In a controller, I''ve created a hash where the keys are the ids: > > @codes = { > ''dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7'' => > {:partner_id => 0, > :partner_name => ''sth'', > :page_number => 1}, > ... > } > > Then i do: > > poll_id = ''"'' + params[''id''] + ''"'' > > The problem is, @codes[poll_id] returns nil. > > Otherwise, @codes["dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7"] > works ok. What am I doing wrong if the keys are the same and explicite > string works while variable doesn''t?They''re not the same; one of them has double quotation marks and the other doesn''t. The string: abc and the string "abc" do not make for the same hash key. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black
On Sun, Mar 19, 2006 at 03:08:28PM +0100, Konlin wrote:> @codes = { > ''dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7'' => > {:partner_id => 0, > :partner_name => ''sth'', > :page_number => 1}, > ... > } > > Then i do: > > poll_id = ''"'' + params[''id''] + ''"''What are those ''"'' + ... + ''"'' for? You are already passing a string when you do params[''id''] so this would be enough: poll_id = params[''id''] @codes[poll_id] or just: @codes[params[''id'']] -- 0x0
Hi KN, W Twoim li?cie datowanym 19 marca 2006 (16:08:46) mo?na przeczyta?: K> What are those ''"'' + ... + ''"'' for? You are already passing a K> string when you do params[''id''] so this would be enough: K> K> poll_id = params[''id''] K> @codes[poll_id] K> or just: @codes[params[''id'']] You''re right. Thanks for answer, I''m a very beginning programmer :) -- K.O.N.L.I.N. konlin@post.pl Kinetic Organism Normally for Logical Infiltration and Nullification, "Is this not what you expected to see?"