What do you mean by programmatically? You can set up a method that will take a file path along the lines of
my_model_instance = MyModel.new
file = File.open(file_path)
my_model_instance.attachment = file
file.close
my_model_instance.save!
#attachment
comes from our Paperclip declaration in our model. In this case, our model looks like
class MyModel < ActiveRecord::Base
has_attached_file :attachment
end
We've done things similar to this when bootstrapping a project.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…