title: Listing files from a remote directory with Rails 3?
body: <p>I have a samba server on our network which contains a number of directories, one of the directories is full of .xls Microsoft Excel documents. </p>
  
  <p>What I am trying to achieve is basically a list of the files within the remote directory which I can then mash up into a link which includes the remote IP. The end result is basically a live table of the files in the directory which the user can click on to open the file they need.</p>
  
  <p>I've read about the following method of doing something similar:</p>
  
  <pre><code>basedir = '.'
  files = Dir.glob("*.xls")
  </code></pre>
  
  <p>What I am trying to work out, is how do I make the basedir a remote IP and also how I would build this into my model/controller.</p>
  
  <p>Ideally I would like to do something like this:</p>
  
  <p><strong>file_controller.rb</strong></p>
  
  <pre><code>class FilesController &lt; ApplicationController
  
   basedir = '192.168.1.1/files/path/to/xlsdocuments/'
  
   def index
   @xls_files = Dir.glob("*.xls")
  
   respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @articles }
   end
  end
  </code></pre>
  
  <p>This would then allow me to loop through the @xls_files in my view.</p>
  
  <p>Is this even remotely possible?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Using the above code in my controller as follows, I don't get any errors but I can't figure out how to display the file names:</p>
  
  <pre><code>class DocumentsController &lt; ApplicationController
  before_filter :authorize, only: [:new, :edit, :update]
  basedir = '192.168.1.1/common/'
    # GET /documents
    # GET /documents.json
    def index
      @documents = Document.all
      @xls_files = Dir.glob("*.xls")
      @xls_files = @xls_files.split('\n')
  
      respond_to do |format|
        format.html # index.html.erb
        format.json { render json: @documents }
      end
    end
  </code></pre>
  
  <p>I'm looping through the file names using the following in my view:</p>
  
  <pre><code>&lt;% @xls_files.each do |xls| %&gt;
   file name
  &lt;% end %&gt;
  </code></pre>
  
  <p>This outputs <code>file name</code>. Any idea how I output the actual filename?</p>