Search code examples
ruby-on-railsruby-on-rails-3downloadpopupwindowsaving-data

saving file to specific location


here is my method to saving file:

 def savefile
    @generator = Generator.new(params[:generator])
    @bigtable = Rails.cache.read("pass")
    doc = "wyniki.csv"
    File.open(doc, "w"){ |f| f << @bigtable}
    send_file(doc, :type => 'text; charset=utf-8')
  end

Currently, my app is saving my file to default downloading browser location - I want to change it - I want initialize pop-up window where user can change filename and location where it should be saved (default downloading browser window)- can anyone help me how to do this?


Solution

  • You're limited in how you can influence where files go. This is a browser setting. If the user has set some option that downloads should automatically go to their download folder, than that is what happens. The only way is to suggest to the browser that it should prompt the user for a location by specifying:

    send_file doc, :type => 'text; charset=utf-8', :disposition => 'attachment'
    

    See the send_file docs for more options.