简体   繁体   中英

Access Paperclip attachments from a rake task

I have a Model in my app which has an attached file for xml files using Thoughtbot's Paperclip.

In my rake task I want to loop through the records, process the XML and marking them as processed. Simple enough. Except I don't know the URL to the attached files

pp xml_record.datafile

just gives the system path like this:

/system/thingstoprocess/datafiles/000/000/001/original/data.xml

and

File.open(xml_record.datafile.url)

gives a no such file or directory error.

How can I pass the file to my Nokogiri class for processing?

Worked it out (by which i mean found on google somewhere)

xml_record.datafile.path

Gives the correct path to read for Nokiogiri. It even works with S3 storage when deployed on heroku (which seems magical)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM