I seem to have often had the problem that I end up writting code where I get strings and symbols mixed up. Maybe this is because I like to do pattern matches alot and end up with strings. Sometimes when you enter a controller the paramter is a string, I forget exactly. I often end up writting stuff like x = x.to_sym it seems like to be safe. I seem to have had problems comparing a string to a symbol and while they where the same identifier, they didn''t match because one was a string and the other a symbol. This has caused me to have bugs that took a while to figure out and had happened quite often. I am wondering if other folks have had this problem as well ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Dec-28 13:23 UTC
Re: mixup between symbols and strings in your code ?
Hi -- On Thu, 28 Dec 2006, surf wrote:> > I seem to have often had the problem that I end up writting code where > I get strings and symbols mixed up. Maybe this is because I like to do > pattern matches alot and end up with strings. Sometimes when you enter > a controller the paramter is a string, I forget exactly. I often end up > writting stuff like x = x.to_sym it seems like to be safe. I seem to > have had problems comparing a string to a symbol and while they where > the same identifier, they didn''t match because one was a string and the > other a symbol. This has caused me to have bugs that took a while to > figure out and had happened quite often. I am wondering if other folks > have had this problem as well ?Yes, I have. Specifically, I sometimes stumble on cases where Rails cares whether something is a symbol vs. string, and which it has to be. At this point I''ve got most of it nailed, but there are one or two that still get me sometimes. For example in: has_many :messages, :through => :discussions :discussions has to be a symbol. If it''s a string, you get the potentially somewhat puzzling error message: "Could not find the association "discussions" in model User". I guess it''s supposed to be a symbol in order to match the symbol-ness of the association names themselves. For some reason I''ve had a hard time remembering this one. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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-/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 -~----------~----~----~----~------~----~------~--~---