为什么在rails 4中使用carrierwave上传文件时我得到“回滚事务"? [英] why when uploading a file using carrierwave in rails 4 i get 'rollback transaction'?
问题描述
我不确定为什么会出现以下错误.我是 Rails 的新手,任何帮助和建议将不胜感激.
- 我正在创建一个招聘网站
- 我正在尝试允许求职者上传他们成功的个人资料图片
- 现在,我正在尝试允许求职者上传他们的简历
- 当我尝试上传简历并保存时,出现以下错误
- 我已经遵循了carrierwave的步骤,但我仍然看不出哪里出错
- 当我尝试上传 pdf 文件或 doc 文件时出现错误提示,上传 jpg 文件工作正常
任何帮助或建议将不胜感激.
终端中的错误信息:
<块引用>回滚事务
在 2015-06-21 20:33:44 +0100 为 127.0.0.1 启动 PATCH "/userjs/1"由 UserjsController#update 处理为 HTML参数:{"utf8"=>"✓", "authenticity_token"=>"KosfL1GqfZM03PFWb2aMuIKKlgPcMLSkITI9VIbjKcA=", "userj"=>{"image"=>#<ActionDispatch::50x50f2000tempfile=#<Tempfile:/var/folders/72/z21dh3tx6jb03dscv7m3wc_h0000gn/T/RackMultipart20150621-9939-7rafcv>,@original_filename="profileimage.jpg", @content_type",@dishead: 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/RackMultipart2019,@TamMultipart2019,@TamMultipart2019,@TamMultipart2019,@TamMultipart2015062.0.05pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"userj[cvattachment]\"; filename=\"00.简历 - 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" = ?限制 1 [["id", 1]](0.1ms) 开始事务(0.1ms) 回滚事务渲染 userjs/_form.html.erb (10.3ms)在布局/应用程序中呈现 userjs/edit.html.erb(11.5 毫秒)在 554ms 内完成 200 OK(查看:539.4ms | ActiveRecord:0.2ms)
uploaders/cvattachment.rb
# 编码:utf-8类 CvattachmentUploader
schema.rb
ActiveRecord::Schema.define(version: 20150621190355) docreate_table "userjs", force: true do |t|t.string "email", 默认: "", null: falset.string "encrypted_password", 默认值: "", null: falset.string "reset_password_token"t.datetime "reset_password_sent_at"t.datetime "remember_created_at"t.integer "sign_in_count",默认值:0,空值:falset.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 "名字"t.string "姓氏"t.整数数字"t.string "城市"t.string "图像"t.string "cvattachment"结尾add_index "userjs", ["email"], 名称: "index_userjs_on_email", 唯一: trueadd_index "userjs", ["reset_password_token"], 名称:"index_userjs_on_reset_password_token",唯一的:true结尾
userj.rb
class Userj
views/userjs/_form.html.erb
<%= simple_form_for(@userj) do |f|%><%= f.error_notification %><div class="form-inputs">图像 <%= f.file_field :image %>cv <%= f.file_field :cvattachment %><%= f.input :firstname %><%= f.input :lastname %><%= f.input :city%>
<div class="form-actions"><%= f.button :submit %>
<%结束%>
views/userjs/show.html.erb
<p><strong>个人资料图片:</strong><div><%= image_tag(@userj.image_url) %></div></p><p><strong>简历:</strong><div><%= image_tag(@userj.cvattachment)%></div></p><div><%= link_to '编辑', edit_userj_path(@userj) %>|<%= link_to '返回', userjs_path %><%= 渲染 'shared/footer_jobseeker' %>
评论 CvattachmentUploader
def extension_white_list%w(jpg jpeg gif png)结尾
重新启动服务器并重试.
I am unsure why i am getting the below error. I am new to rails and any help and advise would be much appreciated.
- i am creating a recruitment site
- i am trying to allow jobseekers to upload their profile image which works successfully
- now, i am trying to allow job seekers to upload their CVs
- when i try to upload a CV and save i get the below error
- i've followed the step of carrierwave but i still can't seem to see where i'm going wrong
- the error prompts up when i try to upload pdf files or doc file, uploading jpg files works fine
any help or advise would be much appreciated.
error message in terminal:
rollback transaction
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)
uploaders/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
views/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 %>
views/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>
Comment these lines from CvattachmentUploader
def extension_white_list
%w(jpg jpeg gif png)
end
Restart server and try again.
这篇关于为什么在rails 4中使用carrierwave上传文件时我得到“回滚事务"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!