I''m trying to take a string in the format "word[field] and word2[field2]...", etc. I have gotten this to work when splitting it in IRB using the following syntax: tempstring.split(/\[|\]/) which returns: ["word", "field", "word2", "field2",...] However, when I attempt to make the exact same call in a rails controller, I get the following error message on the line where String#split is called. "can''t convert Regexp into String" However, I don''t know why it should be trying to convert my Regexp into a string, when the API shows you can use strings or regular expressions. --> http://www.ruby-doc.org/core/classes/String.html#M000818 If you can''t figure it out from what I have given and need more code to look at, let me know. Thanks, JT -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Apr-23 22:04 UTC
Re: String#split works w/ Regexp in IRB, not in rails
> I''m trying to take a string in the format "word[field] and > word2[field2]...", etc. I have gotten this to work when splitting it in > IRB using the following syntax: > > tempstring.split(/\[|\]/)Maybe... tempstring.split(/[\]\[]/) I can''t think of a why irb likes yours, but not rails though...> > which returns: > > ["word", "field", "word2", "field2",...] > > However, when I attempt to make the exact same call in a rails > controller, I get the following error message on the line where > String#split is called. > > "can''t convert Regexp into String" > > However, I don''t know why it should be trying to convert my Regexp into > a string, when the API shows you can use strings or regular expressions. > --> http://www.ruby-doc.org/core/classes/String.html#M000818 > > If you can''t figure it out from what I have given and need more code to > look at, let me know. > > Thanks, > > JT > > -- > Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Stephan Wehner
2007-Apr-23 22:33 UTC
Re: String#split works w/ Regexp in IRB, not in rails
JT Kimbell wrote:> I''m trying to take a string in the format "word[field] and > word2[field2]...", etc. I have gotten this to work when splitting it in > IRB using the following syntax: > > tempstring.split(/\[|\]/) > > which returns: > > ["word", "field", "word2", "field2",...] > > However, when I attempt to make the exact same call in a rails > controller, I get the following error message on the line where > String#split is called.How about you post the code? Maybe tempstring happens to be a regexp for some reason. Stepohan -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Stephan Wehner wrote:> How about you post the code? > > Maybe tempstring happens to be a regexp for some reason. > > StepohanHi, Here is the pertinent code: ---- @querytemp = params[:content_query] #The following code queries the pubmed site and gets their expanded query, while removing their markups. sh = Shell.new(); @querytemp2 = sh.system(''getdetailquery'', @querytemp) @temparray = @querytemp2.split(/\[|\]/) #Split the string at brackets ( [ and ] ) ---- getdetailquery is perl script that expands the query for me, and I can guarantee it works, I''ve tested it in irb, ruby programs, and by itself. All of those variables are used for the first time in that code, so you are seeing them when they are ''initialized''. The error is thrown on the line where the split method is being called. One the line above it, I tried hard-coding the value ''flu'' in for querytemp, and I still get the same error. It doesn''t like me passing a Regexp instead of a string for that :( Thanks, JT -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---