Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Created September 13, 2010 12:59
Show Gist options
  • Save pier-oliviert/577250 to your computer and use it in GitHub Desktop.
Save pier-oliviert/577250 to your computer and use it in GitHub Desktop.
get :upload, :map => "/upload" do
render 'Form.haml'
end
post :upload, :map => "/upload" do
@kitten = Kitten.create(:image => params[:file][:tempfile], :type => params[:type], :age => params[:age])
redirect @kitten.save ? "/kitten/#{@kitten.id}" : "/upload"
end
get :kitten, :map => "/kitten/:id" do
@kitten= Kitten.find_by_id(params[:id])
render 'image.haml'
end
- form_tag '/new-kitten', :class => 'new-kitten', :method => 'post', :enctype => "multipart/form-data" do
- field_set_tag do
%p
= label_tag :name, :class => 'first'
= text_field_tag :name, :value => "kitten's name"
%p
= label_tag :file, :class => 'first'
= file_field_tag :file
%p
= label_tag :age, :class => 'age', :caption => "Age (in Years)"
= text_field_tag :age, :value => 1
%p
= label_tag :type, :class => 'type', :caption => "Type"
= text_field_tag :type, :value => "persan"
%p
- field_set_tag(:class => 'buttons') do
= submit_tag "Add"
= image_tag("/image/#{@kitten.image.id}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment