質問

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?

役に立ちましたか?

解決

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.

他のヒント

This is a browser setting that your application will have no control over. I use Chrome and the setting is in Preferences > Under the Hood. I know that other browsers have similar settings too.

If you check the "Ask where to save each file before downloading" box, then you will get the behavior you're describing.

download location

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top