For the record, I'm working on legacy code and I'm trying to plug a new feature without breaking everything. Right now I have a bunch of files on my server as such:
myapp/public/temp/myfile.doc
The thing is that I want to create a Docfile object from these files in a controller action.
Here is the trimmed down Docfile class:
class DocFile < ActiveRecord::Base
has_attached_file :docs,
:path => "#{Constants::DOCFILES_PATH}:basename.:extension",
:url => "http://#{Constants::SITE_URL}/docs/:basename.:extension"
end
Paperclip has some nice documentation if you upload from a form, but not in my situation.
So how can I "simulate" the fact that I'm uploading a file?
So far I've tried this:
temp_file_url = "correct_rails_root/myapp/public/temp/myfile.doc"
@docfile = DocFile.new :docs => temp_file
But it's not working.
Any pointers would be appreciated!
Edit:
I did this:
temp_file_url = Constants::TEMPORARY_UPLOAD_PATH + "/" + params[:temp_file_upload][:doc]
temp_file = File.new(temp_file_url, "w+")
@docfile = DocFile.new :docs => File.open(temp_file_url)
It's still not working