Hi everybody, I ve got a problem with strings and the class File in rails Indeed, when i try to do this: File.new("archives/sequences/archives-2011.xml") it works perfectly, however when i do string = "archives/sequences/" + @filename => filename being "archives-2011.xml" File.new(string) it doesn''t work! ruby tells me it cannot find the file does anyone could tell me why? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 August 2011 21:22, thelo.g thelo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> string = "archives/sequences/" + @filename => filename being > "archives-2011.xml" > File.new(string) > > it doesn''t work! > ruby tells me it cannot find the fileOutput the value of "string" and see what it is. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 August 2011 21:22, thelo.g thelo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi everybody, > > I ve got a problem with strings and the class File in rails > Indeed, when i try to do this: > File.new("archives/sequences/archives-2011.xml") > it works perfectly, however when i do > string = "archives/sequences/" + @filename => filename being > "archives-2011.xml" > File.new(string) > > it doesn''t work! > ruby tells me it cannot find the fileShow us the exact error message. Copy and paste it into the post, don''t retype it. Colin> > > does anyone could tell me why? > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Colin https://plus.google.com/111605230843729345543/ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No such file or directory - ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml Extracted source (around line #1): 1: <h1>Résultat</h1> <p>id :<%= @result %> <% r = Result.find(@result).nameFile %> <% string = "./archives/results/" + r %> <% f = File.open(string) %> Rails.root: /home/thelo/RoR/ihm_test Application Trace | Framework Trace | Full Trace app/views/pages/print_result.html.erb:1:in `initialize'' app/views/pages/print_result.html.erb:1:in `open'' app/views/pages/print_result.html.erb:1:in `_app_views_pages_print_result_html_erb__106515637_82305240_211210089'' -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
thelo.g thelo wrote in post #1018716:> Hi everybody, > > I ve got a problem with strings and the class File in rails > Indeed, when i try to do this: > File.new("archives/sequences/archives-2011.xml") > it works perfectly, however when i do > string = "archives/sequences/" + @filename => filename being > "archives-2011.xml" > File.new(string) > > it doesn''t work! > ruby tells me it cannot find the fileYou lie: str1 = ''archives/sequences/archives-2011.xml'' @filename = ''archives-2011.xml'' str2 = "archives/sequences/" + @filename puts str1 == str1 --output:-- true -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
And the output of the string is: ActionView::Template::Error (No such file or directory - ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
@7stud no I do not, I might have bad explained the problem. the thing is when i perform the following code: No such file or directory - ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml Extracted source (around line #1): <% r = Result.find(@result).nameFile %> <% string = "./archives/results/" + r %> <% f = File.open(string) %> I got this error: No such file or directory - ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml Extracted source (around line #1): 1: <h1>Résultat</h1> <p>id :<%= @result %> <% r = Result.find(@result).nameFile %> <% string = "./archives/results/" + r %> <% f = File.open(string) %> Rails.root: /home/thelo/RoR/ihm_test Application Trace | Framework Trace | Full Trace app/views/pages/print_result.html.erb:1:in `initialize'' app/views/pages/print_result.html.erb:1:in `open'' app/views/pages/print_result.html.erb:1:in `_app_views_pages_print_result_html_erb__106515637_82305240_211210089'' and in the console ActionView::Template::Error (No such file or directory - ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml So when i replace string by "Archives-2011-08-26-09-56-00-UTC.xml" everything is ok, no problem. I just want to understand why and fix this problem Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
full patch of "archives" is? if under rails root, then change code to string = Rails.root.to_s+''/archives/results/''+r or write down full path to archives directory tom On Aug 26, 2011, at 23:23 , thelo.g thelo wrote:> @7stud no I do not, I might have bad explained the problem. the thing is > when i perform the following code: > > No such file or directory - > ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml > Extracted source (around line #1): > > <% r = Result.find(@result).nameFile %> > <% string = "./archives/results/" + r %> > <% f = File.open(string) %> > > I got this error: > No such file or directory - > ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml > Extracted source (around line #1): > > 1: <h1>Résultat</h1> > <p>id :<%= @result %> > > > <% r = Result.find(@result).nameFile %> > <% string = "./archives/results/" + r %> > <% f = File.open(string) %> > > > Rails.root: /home/thelo/RoR/ihm_test > > Application Trace | Framework Trace | Full Trace > app/views/pages/print_result.html.erb:1:in `initialize'' > app/views/pages/print_result.html.erb:1:in `open'' > app/views/pages/print_result.html.erb:1:in > `_app_views_pages_print_result_html_erb__106515637_82305240_211210089'' > > and in the console > ActionView::Template::Error (No such file or directory - > ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml > > > So when i replace string by "Archives-2011-08-26-09-56-00-UTC.xml" > everything is ok, no problem. > I just want to understand why and fix this problem > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I tried but it doesn''t work, is it possible that the mistake has a ling with \n at the end of r? because when I do: puts ''"'' + r + ''"'' I get "Archives-2011-08-26-09-56-00-UTC.xml " -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thelo.g thelo wrote in post #1018731:> @7stud no I do not, I might have bad explained the problem. the thing is > when i perform the following code: > > No such file or directory - > ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml > Extracted source (around line #1): > > <% r = Result.find(@result).nameFile %> > <% string = "./archives/results/" + r %> > <% f = File.open(string) %> > > I got this error: > No such file or directory - > ./archives/results/Archives-2011-08-26-09-56-00-UTC.xml > Extracted source (around line #1): > > 1: <h1>Résultat</h1> > <p>id :<%= @result %> > > > <% r = Result.find(@result).nameFile %> > <% string = "./archives/results/" + r %> >> So when i replace string by >> "Archives-2011-08-26-09-56-00-UTC.xml"(''./archives/results'' + r) is not the same thing as "Archives-2011-08-26-09-56-00-UTC.xml" You have proved nothing. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
I meant when i replace string by "./archives/results/Archives-2011-08-26-09-56-00-UTC.xml", which is normally similar to ''./archives/results'' + r -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 26, 2011, at 23:51 , thelo.g thelo wrote:> I tried but it doesn''t work, is it possible that the mistake has a ling > with \n at the end of r? because when I do: > puts ''"'' + r + ''"'' > > I get > "Archives-2011-08-26-09-56-00-UTC.xml > "\n doesn''t matter ruby-1.8.7-p174 :006 > File.new("./testfile",''w'') => #<File:./testfile> ruby-1.8.7-p174 :007 > File.new("./testfile\n",''w'') => #<File:./testfile>you just cripple the filename ..> -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
What do you mean? and if this is the case, how can I fix it? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thelo.g thelo wrote in post #1018739:> I tried but it doesn''t work, is it possible that the mistake has a ling > with \n at the end of r? because when I do: > puts ''"'' + r + ''"'' > > I get > "Archives-2011-08-26-09-56-00-UTC.xml > "It''s not only possible, that is exactly what is at the end of r. When you are having such a problem, it is easier to see what the string actually contains by doing one of the following: 1) puts "-->#{some_var}<---" 2) p r which is the same as: puts r.inspect Here is an example: str = "hello world" p str --output:-- "hello\nworld" And of course the newline makes a difference in the file name. You can test that yourself: some_file = "html.htm" File.open(some_file) do |f| puts f.read end Once you get that to work with a file on your file system, try adding a \n to the end. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tom Meinlschmidt wrote in post #1018745:> > > \n doesn''t matter > > ruby-1.8.7-p174 :006 > File.new("./testfile",''w'') > => #<File:./testfile> > ruby-1.8.7-p174 :007 > File.new("./testfile\n",''w'') > => #<File:./testfile >> > > you just cripple the filename .. >Really?? I don''t see a crippled filename. .. . . . . . . -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> => #<File:./testfile> >> > > > > you just cripple the filename .. > > > > Really?? I don''t see a crippled filename. >You don''t see that > is in the next line? the \n char is being interpreted. Just do: string.chomp This should work (as suggested before): string = Rails.root.to_s+''/archives/results/''+r.chomp If you really want to be portable you should be writing file paths like: File.join(Rails.root,"archives","results",r.chomp) -- ----)(----- Luis Mondesi Maestro Debiano ----- START ENCRYPTED BLOCK (Triple-ROT13) ------ Gur Hohagh [Yvahk] qvfgevohgvba oevatf gur fcvevg bs Hohagh gb gur fbsgjner jbeyq. ----- END ENCRYPTED BLOCK (Triple-ROT13) ------ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you guys a lot, 7stud was right, I added chomp and it works! Hence, \n makes a difference. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Mondesi wrote in post #1018782:>> => #<File:./testfile > >> >> >> > >> > you just cripple the filename .. >> > >> >> Really?? I don''t see a crippled filename. >> > > You don''t see that > is in the next line? >Yes, I see exactly that.> the \n char is being > interpreted. >No kidding. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.