# Migrations to load photos with attachment\_fu?

**URL:** <https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788>\
**Category:** Rails\
**Created:** [November 10, 2007, 3:05pm UTC](https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788 "2007-11-10T15:05:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2007, 3:05pm UTC](https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788/1 "2007-11-10T15:05:57Z")

</div>

I’ve been studying the web this morning and trying to find examples  
where someone has imported photo ‘test data’ using attachment\_fu?  
I’ve tried this in many was using a traditional data migration like  
I’ve done hundreds of times and nothing comes in? Attachment\_fu put a  
record to the database, but there is so supporting file behind it.  
I enclose what my migration looks like for one record.

newrecord = Vendphoto.create(  
:vendor\_id =\> ‘1’,  
:title =\> ‘Add Test Vendphoto 1’,  
:content\_type =\> ‘image/jpeg’,  
:size =\> ‘38414’,  
:width =\> ‘230’,  
:height =\> ‘200’,  
:geo\_lat =\> ‘27.9686’,  
:geo\_long =\> ‘-97.0943’,  
:filename =\> ‘KathyTest.jpg’)  
newrecord.save!  
I ‘presumed’ some of this information by manually adding a photo and  
then looking at the MySQL record that was created. I experimented  
putting the photo in question ‘KathyTest.jpg’ in the \public\images  
and many other places. I load the ‘Vendphoto’ record in the database  
BUT the actual photo doesn’t exist in my \Public\Images\Vendphoto (as  
if I had done this manuall).  
Thank you,  
Kathy  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 10, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788/2 "2007-11-10T15:50:23Z")

</div>

On 10-Nov-07, at 9:04 AM, removed\_email\_address@domain.invalid wrote:

> I’ve been studying the web this morning and trying to find examples  
> where someone has imported photo ‘test data’ using attachment\_fu?  
> I’ve tried this in many was using a traditional data migration like  
> I’ve done hundreds of times and nothing comes in? Attachment\_fu put a  
> record to the database, but there is so supporting file behind it.  
> I enclose what my migration looks like for one record.

here’s an example of loading images in a migration.

```
 filename = "#{some_path}some_file.gif"
 image = Image.create(:uploaded_data =>

```

ActionController::TestUploadedFile.new(filename, ‘image/gif’))

the trick is using the ActionController:TestUploadFile to simulate a  
file upload request.

Cheers,  
Jodi

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 11, 2007, 2:45pm UTC](https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788/3 "2007-11-11T14:45:52Z")

</div>

Jodi,  
I’m so excited about having the ability to load photos with  
migrations! Thank you for responding. I took your code and modified my  
original routine as shown:

def self.up  
down  
filename = “#{‘c:/temp/’}MollyTest.gif”  
newrecord = Ephoto.create(  
:uploaded\_data =\>  
ActionController::TestUploadedFile.new(filename, ‘image/gif’),  
:eitem\_id =\> ‘1’,  
:title =\> ‘Add Test Ephoto 1’,  
:size =\> ‘1536’,  
:width =\> ‘100’,  
:height =\> ‘69’,  
:geo\_lat =\> ‘27.9686’,  
:geo\_long =\> ‘-97.0943’)  
newrecord.save!  
end

The problem is a I get a "rake aborted! uninitialized constant  
ActionController::TestUploadedFile " message when I try to run the  
migration. Any suggestions are greatly appreciated.  
Kathleen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 13, 2010, 3:48pm UTC](https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788/4 "2010-02-13T15:48:19Z")

</div>

I just put this here since couldn’t find it anywhere else on the net:

require “action\_controller/test\_process”

def self.up  
…  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 14, 2010, 2:39am UTC](https://www.ruby-forum.com/t/migrations-to-load-photos-with-attachment-fu/119788/5 "2010-02-14T02:39:11Z")

</div>

test
