我正在尝试上传文件并将其保存到服务器,文件类型将是文档,主要是doc / docx或Pages'file
为什么文件未保存,型号为Grade
,属性为Answer
?
这是我的Schema.rb文件
ActiveRecord::Schema.define(:version => 20110920230706) do
create_table "assignments", :force => true do |t|
t.string "name"
t.string "instructions"
t.date "due"
t.integer "scribd_id"
t.decimal "score"
t.datetime "created_at"
t.datetime "updated_at"
t.binary "handout"
end
create_table "grades", :force => true do |t|
t.integer "assignment_id"
t.integer "user_id"
t.integer "scribd_id"
t.decimal "score"
t.text "note"
t.datetime "created_at"
t.datetime "updated_at"
t.string "answer_file_name"
t.string "answer_content_type"
t.integer "answer_file_size"
t.datetime "answer_updated_at"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
Grade.rb
class Grade < ActiveRecord::Base
belongs_to :assignment
has_attached_file :answer
end
Show.html.erb
<%= stylesheet_link_tag "assignments" %>
<p id="notice"><%= notice %></p>
<div class="show">
<h2 id="title"><%= @assignment.name %></h2>
<div id="directions_container">
<h3>Directions - <div id="directions"><%= @assignment.instructions %></div> </h3>
<div class="turn_in_container">
<div class="turn_in_box prepare_for_turn_in" id="turn_in_box">
<div id="label">
<h4 id="turn_in_assignment">Turn In Assignment</h4>
<h6 id="drag">(You can just drag it in here)</h6>
</div>
</div>
<%= form_for @grade, :html => { :multipart => true, :id => "form"} do |f| %>
<%= f.file_field :answer, :id => "file" %>
<% end %>
</div>
</div>
assignments.js.coffee
$(document).ready ->
$("#file").mouseenter ->
$("#turn_in_box").css "border", "2px solid #D9D9D9"
$("#turn_in_box").css "background", "#D9D9D9"
$("#turn_in_box").css "color", "#393939"
$("#turn_in_box").css "cursor", "pointer"
$("#turn_in_box").css "box-shadow" ,"0px 0px 0px transparent"
$("#file").mouseleave ->
$("#turn_in_box").css "border", "2px solid #D9D9D9"
$("#turn_in_box").css "background", "#393939"
$("#turn_in_box").css "color", "#D9D9D9"
$("#turn_in_box").css "cursor", "default"
$("#file").bind 'dragover', (evt) ->
evt.stopPropagation()
evt.preventDefault()
$("#file").bind 'drop', ->
$("#drag").css "display", "none"
$("#turn_in_assignment").text "Turning In Assignment..."
$("#form").submit()
development.log
Started GET "/assignments/2" for 127.0.0.1 at 2011-09-20 16:08:38 -0700
Processing by AssignmentsController#show as HTML
Parameters: {"id"=>"2"}
←[1m←[36mUser Load (0.0ms)←[0m ←[1mSELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1←[0m
←[1m←[35mAssignment Load (0.0ms)←[0m SELECT "assignments".* FROM "assignments" WHERE "assignments"."id" = ? LIMIT 1
←[1m←[36mGrade Load (0.0ms)←[0m ←[1mSELECT "grades".* FROM "grades" WHERE "grades"."assignment_id" = 2 AND "grades".
Rendered assignments/show.html.erb within layouts/application (50.0ms)
Completed 200 OK in 183ms (Views: 132.0ms | ActiveRecord: 1.0ms)
Started GET "/assets/assignments.css?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /assignments.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /jquery.js - 304 Not Modified (1ms)
Started GET "/assets/grades.css?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /grades.css - 304 Not Modified (0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/assignments.js?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /assignments.js - 304 Not Modified (1ms)
Started GET "/assets/assignments.js.js?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /assignments.js.js - 304 Not Modified (0ms)
Started GET "/assets/grades.js?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /grades.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2011-09-20 16:08:39 -0700
Served asset /application.js - 304 Not Modified (0ms)
Started PUT "/grades/2" for 127.0.0.1 at 2011-09-20 16:08:47 -0700
Processing by GradesController#update as HTML
Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"/MpatBt5HIrsYPF0PKeyhfsQjY+Z1yDXMRtZjW+fHA8=", "id"=>"2"}
←[1m←[35mGrade Load (0.0ms)←[0m SELECT "grades".* FROM "grades" WHERE "grades"."id" = ? LIMIT 1 [["id", "2"]]
[paperclip] Saving attachments.
Redirected to http://localhost:3000/grades/2
Completed 302 Found in 51ms
Started GET "/grades/2" for 127.0.0.1 at 2011-09-20 16:08:47 -0700
Processing by GradesController#show as HTML
Parameters: {"id"=>"2"}
←[1m←[36mGrade Load (1.0ms)←[0m ←[1mSELECT "grades".* FROM "grades" WHERE "grades"."id" = ? LIMIT 1←[0m [["id", "2"
Rendered grades/show.html.erb within layouts/application (11.0ms)
Completed 200 OK in 28ms (Views: 25.0ms | ActiveRecord: 1.0ms)