Skip to content

Instantly share code, notes, and snippets.

@burningTyger
Forked from lchanmann/app.rb
Created January 28, 2011 08:07
Show Gist options
  • Save burningTyger/799982 to your computer and use it in GitHub Desktop.
Save burningTyger/799982 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'haml'
require 'sinatra'
require 'sinatra/flash'
require 'file_uploader'
enable :sessions
get '/' do
haml :index
end
post '/upload' do
FileUploader.create.save(params[:file]) do |path|
flash[:upload] = "#{path} is saved."
end
redirect '/'
end
__END__
@@ layout
%html
%head
%title File Uploader
%body
= yield
@@ index
%h1 File Uploader
- if flash[:upload]
%div{:style => 'color:green'}= flash[:upload]
%form{:action => '/upload', :method => 'post', :enctype => 'multipart/form-data'}
%label{:for => 'file'} Select file:
%input{:type => 'file', :id => 'file', :name => 'file'}
%input{:type => 'submit', :value => 'Upload'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment