The Depot Application

The Depot Application

23.9 Layouts and Components 23.7 Working with Nonmodel Fields

23.8 Uploading Files to Rails Applications

rails generate model picture comment:string name:string content_type:string data:binary
      invoke  active_record
      create    db/migrate/20100807132246_create_pictures.rb
      create    app/models/picture.rb
      invoke    test_unit
      create      test/unit/picture_test.rb
      create      test/fixtures/pictures.yml
cp -v /home/rubys/git/awdwr/data/code/e1/views/db/migrate/*pictures.rb db/migrate/*pictures.rb
`/home/rubys/git/awdwr/data/code/e1/views/db/migrate/003_create_pictures.rb' -> `db/migrate/20100807132246_create_pictures.rb'
cp -v /home/rubys/git/awdwr/data/code/e1/views/app/models/picture.rb app/models
`/home/rubys/git/awdwr/data/code/e1/views/app/models/picture.rb' -> `app/models/picture.rb'
rake db:migrate
mv 20100807132246_create_pictures.rb 20100301000004_create_pictures.rb
(in /home/rubys/git/awdwr/work-188/view)
==  CreatePictures: migrating =================================================
-- create_table(:pictures)
   -> 0.0017s
==  CreatePictures: migrated (0.0018s) ========================================
 
cp -vr /home/rubys/git/awdwr/data/code/e1/views/app/views/upload app/views
`/home/rubys/git/awdwr/data/code/e1/views/app/views/upload' -> `app/views/upload'
`/home/rubys/git/awdwr/data/code/e1/views/app/views/upload/show.html.erb' -> `app/views/upload/show.html.erb'
`/home/rubys/git/awdwr/data/code/e1/views/app/views/upload/get.html.erb' -> `app/views/upload/get.html.erb'
`/home/rubys/git/awdwr/data/code/e1/views/app/views/upload/save.html.erb' -> `app/views/upload/save.html.erb'
edit app/views/upload/get.html.erb
<%= error_messages_for("picture") %>
 
<%= form_for(:picture, 
            :url => {:action => 'save'}, 
            :html => { :multipart => true }) do |form| %>
 
    Comment:             <%= form.text_field("comment") %><br/>
    Upload your picture: <%= form.file_field("uploaded_picture") %><br/>
 
    <%= submit_tag("Upload file") %>
<% end %>
get /upload/get
DEPRECATION WARNING: error_messages_for was removed from Rails and is now available as a plugin. Please install it with `rails plugin install git://github.com/rails/dynamic_form.git`. (called from _app_views_upload_get_html_erb__274970287__615716628_0 at /home/rubys/git/awdwr/work-188/view/app/views/upload/get.html.erb:1)
Comment:
Upload your picture:

23.9 Layouts and Components 23.7 Working with Nonmodel Fields