Forum: Ruby on Rails trouble with Dir.chdir

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
875db27b8f97621cdb6c3e4a5e58b075?d=identicon&s=25 unknown (Guest)
on 2006-05-13 15:14
(Received via mailing list)
Hi, folks

I wroted the codes below.

I have the trouble with the line start from "Dir.chdir".

When I run this code, the FTP of photos is successfuly done.
But, the display of browser is white out.

When I comment out the line start from "Dir.chdir",
the trouble doesn't happen.

Is there anything wrong with my usage of "Dir.chdir"?

 def ftp_photo
   $basedir = "/home/yosuke/public_html/myalbum/albums/"
   $tempdir = "/home/yosuke/public_html/testing/tempPhoto/"

   targetdir = params[:targetdir]
   @targetdir = params[:targetdir]

   fhostname = 'hogefpt.co.jp'
   fusername = 'hoge'
   fuserpass = 'hogehoge'
   fbasedir = '/hogehoge/'

   targetdirpath = $tempdir + targetdir
   Dir.chdir targetdirpath

   begin
     ftp = Net::FTP.open(fhostname,fusername,fuserpass)
     @messageftpconnect = "connected"
   rescue
     @messageftpconnect = "failed"
   end

   ftp.chdir(fbasedir)

   begin
     ftp.mkdir(targetdir)
     @messageftpmkdir = "the directory was created"
   rescue
     @messageftpmkdir = "the directory already exists"
   end

   ftp.chdir(targetdir)

   Dir::glob("./*.jpg").each {|f|
     ftp.put(f)
   }

   ftp.close

   FileUtils.rm_rf(targetdirpath)

 end


ftp_photo.rhtml

start FTP<br />

<%= @messageftpconnect  %><br />


<%= @messageftpmkdir  %><br />

layout file

<html>
 <head>
  <title>my tool</title>
  <%= stylesheet_link_tag "mytool", :media => "all" %>
  <meta http-equiv="content-type" content="Mime-Type; charset=UTF-8">
 </head>
 <body>
  <div id="banner">
   my tools
  </div>
  <div id="column">
  <div id="side">
   <a href="http://www">home</a><br />
  </div>
  <div id="main">
   <% if @flash[:notice] -%>
    <div id="notice"><%= @flash[:notice] %></div>
   <% end %>
   <%= @content_for_layout %>
  </div>
  </div>
 </body>
</html>

#Sorry japanese readers,
#I sent the same mail to the ML for japanese rails users

-----
Yosuke Suzuki from Japan
This topic is locked and can not be replied to.