S3asy
Rails gem for associating an s3 object with an active record model
Install
gem install robertoles-s3asy --source http://gems.github.com
Usage
You want to create an active record model ‘product’ which has an attribute ‘image’ which is an s3 object. First create a migration for your model and specify a string column for the image attribute followed by _name…
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.string :image_name
t.
end
end
def self.down
drop_table :products
end
end
Now you will need to specify your s3 credentials, to do this add the file /config/amazon_s3.yml
test:
access_key_id: your_access_key_id
secret_access_key: your_secret_access_key
Finally create the association in your model, specifying the bucket on s3 the object is stored in…
class Product < ActiveRecord::Base
has_s3object :image, :bucket => 'bucket'
end
License
Copyright © 2010 Robert Oles
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.