You are here: Browse Railsplugins Attachment Fu Fixtures
This plugin enables models that implement attachment_fu to also use fixtures. It processes and stores the attachment file as if it had being uploaded. Useful if you use fixtures in your tests/specs and want to test with real attachments, but especially useful for, and intended to be used as, seed data fixtures.
Fixtures are simple and convenient for seed/sample/dev data; they have built-in tasks (rake db:fixtures:load) and are automatically generated with scaffolds.
Great for preview and staging environments where you want content and attachments to be available. Images, for example, can help a fair deal with presentation (think about your client viewing how the site is evolving) and to present a more realistic experience. Perfect for production seed data that requires attachments.
Also useful in development, for when you use fixtures to populate the interface. Essential for front-end development, and to get a quick glance at the interface.
To use, all you have to do is add a fixture for the attachment with an ‘attachment_file’ field, pointing to your attachment file. That’s it!
= fixtures/images.yml beach: title: kho phi phi beach attachment_file: test/images/maya.png
All other fields required by attachment_fu will be automatically filled in. If explicitly specified in the fixture though, they take precedence.
belongs_to associations are specified just like in normal fixtures. For example, for an image that belongs to a user:
= fixtures/images.yml harbour: title: victoria harbour attachment_file: test/images/harbour.png user: mynyml
To load the fixture data, cd to RAILS_ROOT and call
rake db:fixtures:load #for test/fixtures
rake spec:db:fixtures:load #for spec/fixtures
TIP: If you also use fixtures for tests/specs, I recommend you create a separate set of fixtures to use as seed data. You can store them in another directory (e.g. db/dev_data, db/fixtures, or even categorize them per environment) and create a custom rake task to load them (you can copy-paste rails’s from railties/lib/tasks/databases.rake and simply change the path).
If you’re using edge rails from the github repository, you can install with the built in plugin installation command
./script/plugin install git://github.com/mynyml/attachment_fu_fixtures.git
Otherwise you can install manually with just a few steps
o download the tarball at http://github.com/mynyml/attachment_fu_fixtures/tarball/master
into your vendor/plugins directory
o extract it
o rename the extracted directory to attachment_fu_fixtures
o delete the file you downloaded (you won't need it anymore)
TIP: If you’re on linux, the terminal commands for the above steps are:
from witin your vendor/plugins directory:
wget http://github.com/mynyml/attachment_fu_fixtures/tarball/master;
tar zxvf mynyml-attachment_fu_fixtures-.tar.gz;
mv mynyml-attachment_fu_fixtures-/ attachment_fu_fixtures;
rm mynyml-attachment_fu_fixtures-*.tar.gz
Tested with:
To run specs:
- Thanks to Patrick Crosby for submitting a patch for the model_class bug - Thanks to Jeff Webb for patching HABTM and STI handling
If you have suggestions, comments, a patch, a git pull request, rants, doc fixes/improvements, etc., feel free to contact me: mynyml at gmail, irc.freenode.net #rubyonrails
And if you find this plugin useful… I especially appreciate emails mentioning what sites/projects it’s been used with
Happy Hacking!
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly