我不确定为什么我会收到以下错误。我是rails的新手,任何帮助和建议都会非常感激。
任何帮助或建议将不胜感激。
终端错误消息:
回滚交易
Started PATCH "/userjs/1" for 127.0.0.1 at 2015-06-21 20:33:44 +0100
Processing by UserjsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"KosfL1GqfZM03PFWb2aMuIKKlgPcMLSkITI9VIbjKcA=", "userj"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007fb75c2d5f58 @tempfile=#<Tempfile:/var/folders/72/z21dh3tx6jb03dscv7m3wc_h0000gn/T/RackMultipart20150621-9939-7rafcv>, @original_filename="profileimage.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"userj[image]\"; filename=\"profileimage.jpg\"\r\nContent-Type: image/jpeg\r\n">, "cvattachment"=>#<ActionDispatch::Http::UploadedFile:0x007fb75c2d5e90 @tempfile=#<Tempfile:/var/folders/72/z21dh3tx6jb03dscv7m3wc_h0000gn/T/RackMultipart20150621-9939-uh56yj>, @original_filename="00. Resume - A. Richill Tamakloe.pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"userj[cvattachment]\"; filename=\"00. Resume - A. Richill Tamakloe.pdf\"\r\nContent-Type: application/pdf\r\n">, "firstname"=>"aknorbea", "lastname"=>"artloe", "city"=>"accra", "language"=>"french | gary carr"}, "commit"=>"Update Userj", "id"=>"1"}
Userj Load (0.1ms) SELECT "userjs".* FROM "userjs" WHERE "userjs"."id" = ? LIMIT 1 [["id", 1]]
(0.1ms) begin transaction
(0.1ms) rollback transaction
Rendered userjs/_form.html.erb (10.3ms)
Rendered userjs/edit.html.erb within layouts/application (11.5ms)
Completed 200 OK in 554ms (Views: 539.4ms | ActiveRecord: 0.2ms)
上传/ cvattachment.rb
# encoding: utf-8
class CvattachmentUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
schema.rb
ActiveRecord::Schema.define(version: 20150621190355) do
create_table "userjs", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", 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, null: false
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"
t.string "firstname"
t.string "lastname"
t.integer "number"
t.string "city"
t.string "image"
t.string "cvattachment"
end
add_index "userjs", ["email"], name: "index_userjs_on_email", unique: true
add_index "userjs", ["reset_password_token"], name: "index_userjs_on_reset_password_token", unique: true
end
userj.rb
class Userj < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :adverts, through: :forms
has_many :forms
mount_uploader :image, ImageUploader
mount_uploader :cvattachment, CvattachmentUploader
end
视图/ userjs / _form.html.erb
<%= simple_form_for(@userj) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
image <%= f.file_field :image %>
cv <%= f.file_field :cvattachment %>
<%= f.input :firstname %>
<%= f.input :lastname %>
<%= f.input :city %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
视图/ userjs / show.html.erb
<div>
<p>
<strong>profile image:</strong>
<div><%= image_tag(@userj.image_url) %></div>
</p>
<p>
<strong>cv:</strong>
<div><%= image_tag(@userj.cvattachment) %></div>
</p>
<div>
<%= link_to 'Edit', edit_userj_path(@userj) %> |
<%= link_to 'Back', userjs_path %>
</div>
<%= render 'shared/footer_jobseeker' %>
</div>
答案 0 :(得分:1)
评论CvattachmentUploader
def extension_white_list
%w(jpg jpeg gif png)
end
重新启动服务器,然后重试。