Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Feb 12, 2012
0 parents commit 87322b1
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 0 deletions.
Binary file added development.db
Binary file not shown.
47 changes: 47 additions & 0 deletions main.rb
@@ -0,0 +1,47 @@
require 'sinatra'
require 'data_mapper'
require 'dm-paperclip'

APP_ROOT = File.expand_path(File.dirname(__FILE__))

DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")

class Image
include DataMapper::Resource
include Paperclip::Resource

property :id, Serial

has_attached_file :file,
:url => "/files/:id.:extension",
:path => "#{APP_ROOT}/public/files/:id.:extension"

end

DataMapper.finalize
DataMapper.auto_upgrade!

def make_paperclip_mash(file_hash)
mash = Mash.new
mash['tempfile'] = file_hash[:tempfile]
mash['filename'] = file_hash[:filename]
mash['content_type'] = file_hash[:type]
mash['size'] = file_hash[:tempfile].size
mash
end

get '/' do
haml :upload
end

get '/' do
Image.first
haml :pr
end

post '/upload' do
halt 409, "File seems to be emtpy" unless params[:file][:tempfile].size > 0
@resource = Image.new(:file => make_paperclip_mash(params[:file]))
@resource.save
"Complete!"
end
Binary file added public/files/1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/files/2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/files/3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/files/4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions views/pr.haml
@@ -0,0 +1,3 @@
%form{:action=>'/print', :method=>'POST'}

%img{:src => @resource.file.url }
3 changes: 3 additions & 0 deletions views/upload.haml
@@ -0,0 +1,3 @@
%form{:action=>"/upload",:method=>"post" ,:enctype=>"multipart/form-data"}
%input{:type=>"file",:name=>"file"}
%input{:type=>"submit",:value=>"Upload"}

0 comments on commit 87322b1

Please sign in to comment.