title: link to delete a file from a directory
body: <p>In a rails 2.3.8 app i am trying to write a link in a view that passes the filename to the method in a controller that deletes a file from a directory. Haven't been able to get the syntax right. I've updated the code below to reflect Tobias' suggestions. It works, except for file names that have spaces in them.</p>
  
  <p>In the documents_conroller.rb file is the following method:</p>
  
  <pre><code>def file_cleanup
    File.delete("#{RAILS_ROOT}/public/downloads/#{params[:filename].gsub /[^\.\w]/, ''}") 
    redirect_to :action =&gt; :index
  end
  </code></pre>
  
  <p>In the view:</p>
  
  <pre><code>&lt;% @files.each do |f| %&gt;
     &lt;% str = f.gsub(/^.*\//, '') %&gt;
     &lt;tr&gt;
        &lt;td&gt;
            &lt;%=str%&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;%= link_to "Del", file_cleanup_path(:filename =&gt; str) %&gt;
        &lt;/td&gt;
     &lt;/tr&gt;
  &lt;% end -%&gt;
  </code></pre>
  
  <p>In the routes file:</p>
  
  <pre><code>map.file_cleanup '/file_cleanup', :controller =&gt; 'documents', :action =&gt; 'file_cleanup'
  </code></pre>
  
  <p>Thanks for your help!</p>