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/20120629192405_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/edition3/data/code/e1/views/db/migrate/*pictures.rb db/migrate/*pictures.rb
`/home/rubys/git/awdwr/edition3/data/code/e1/views/db/migrate/003_create_pictures.rb' -> `db/migrate/20120629192405_create_pictures.rb'
cp -v /home/rubys/git/awdwr/edition3/data/code/e1/views/app/models/picture.rb app/models
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/models/picture.rb' -> `app/models/picture.rb'
rake db:migrate
mv 20120629192405_create_pictures.rb 20110711000004_create_pictures.rb
==  CreatePictures: migrating =================================================
-- create_table(:pictures)
   -> 0.0018s
==  CreatePictures: migrated (0.0019s) ========================================
 
cp -vr /home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/upload app/views
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/upload' -> `app/views/upload'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/upload/save.html.erb' -> `app/views/upload/save.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/upload/show.html.erb' -> `app/views/upload/show.html.erb'
`/home/rubys/git/awdwr/edition3/data/code/e1/views/app/views/upload/get.html.erb' -> `app/views/upload/get.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__1959925560_70201630206240_0 at /home/rubys/git/awdwr/edition3/work-30/view/app/views/upload/get.html.erb:1)
Comment:
Upload your picture:

23.9 Layouts and Components 23.7 Working with Nonmodel Fields