Skip to content

Instantly share code, notes, and snippets.

@adjohu
Created January 15, 2012 22:15
Show Gist options
  • Save adjohu/1617686 to your computer and use it in GitHub Desktop.
Save adjohu/1617686 to your computer and use it in GitHub Desktop.
post :add do
if (file = params[:file])
image = Image.create(
:name => 'abc',
:gallery_id => 1
)
image.upload(file)
end
end
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