Jeff Pritchard wrote:
> I'm working on an app that includes the feature to allow user to
> download a csv file of their data.
> 
> I've got it working on my local machine, but when I deploy it, the link
> I'm making doesn't work for doing the download.  The file IS being
> created in the location I'm intending, but the file download only works
> on my local machine and not on the server.
> 
> This is probably more correctly an html or unix/linux issue or something
> to do with how I'm constructing my path, but I don't know enough about
> what's wrong to tell for sure.
> 
> Here's the relevant code that makes the link:
> 
>     @temp_download_file_path = "/tmp/#{modified_email}.csv"
> ...
>     FasterCSV.open(@temp_download_file_path, "w") do |csv|
>       @contacts.each do |one_contact|
>          ...csv stuff that is working and not relevant
>        end
>      end
> 
>     render :update do |page|
>       page.replace_html 'div_for_csv_link', "<a
> href='file:[EMAIL PROTECTED]' target='_blank' >Download the
> file here</a>"
>     end
> 
> 
> The resulting link looks like this when you copy it or hover over it:
> 
> file:///tmp/fred_at_creditcards_and_loans_com.csv
> 
> Do I need to put the file in a different place in order for the
> permissions to work?  Should it be file: or http:// before the file
> name.
> 
> Thanks for your help on this. You never really realize how incredibly
> diverse the knowledge you need for developing something until you dig
> into something like this that sounds simple, but is slightly outside the
> realm of what you've done before.
> 
> thanks,
> jp

A link with file:// will only work if the file is on the current
machine. For example:

file:///mypath/myfile

will download a file from /mypath/myfile *on the local machine* if it
exists.

What you are probably wanting is to create the file in a temporary
directory as you have done, but then serve it up with a proper link.

You might want to look at send_file or send_data to read the contents
from the file and directly send it to the users browser. you will have
to put this inside another action.

HTH

Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to