Created
January 15, 2012 22:15
-
-
Save adjohu/1617686 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post :add do | |
if (file = params[:file]) | |
image = Image.create( | |
:name => 'abc', | |
:gallery_id => 1 | |
) | |
image.upload(file) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Image | |
include DataMapper::Resource | |
belongs_to :gallery | |
has 1, :user, :through => :gallery | |
# property <name>, <type> | |
property :id, Serial | |
property :name, String | |
property :filename, String | |
property :created_on, DateTime | |
def upload(file) | |
# Get upload path and create it if needed | |
file_dir = self.user.get_file_dir | |
FileUtils.mkdir_p(file_dir) | |
filename = file[:filename] | |
tmpfile = file[:tempfile] | |
#Upload is done here... | |
@filename = filename | |
self.save | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment