Acts as file
acts_as_file
makes your field act as a file.
The content of the field is stored into a file on calling #save
method,
and is loaded from the file on calling its accessor method.
Installation
Add the following to your Gemfile
:
gem 'acts_as_file'
And then execute:
$ bundle
Examples
ActiveRecord is not required, but let me write an example for it.
class Post < ActiveRecord::Base
include ActsAsFile
def filename
"posts/#{self.id}_body.txt"
end
acts_as_file :body => self.instance_method(:filename)
end
post = Post.new
post.body = 'content'
post.save
post = Post.first
puts post.body
post.destroy
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright
- Copyright (c) 2014 Naotoshi Seo. See LICENSE for details.