我的上傳在我的本地機器上完美工作,但無法在生產服務器上工作。代碼是相同的,不存在未提交的提交等Rails應用程序Carrierwave上傳開發工作,但停止開發生產
這裏是我的本地機器上會發生什麼:
Started POST "/admin/projects" for 127.0.0.1 at 2015-10-08 17:17:11 +0300
Processing by Admin::ProjectsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BLD9208mLcwkXDjyqYbf7sFBs51mgrGAGZYFIi2VT+jstdj0FdC0PB+DmrX3epz7m7UU5LXmN+961/9EN7ExQA==", "projectphotos"=>[#<ActionDispatch::Http::UploadedFile:0x007fbffb8133d8 @tempfile=#<Tempfile:/var/folders/dz/tf2gsysx18n_cj_m1xqbpyw80000gn/T/RackMultipart20151008-24531-w7z0b4.jpg>, @original_filename="_MG_9839.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"_MG_9839.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007fbffb813360 @tempfile=#<Tempfile:/var/folders/dz/tf2gsysx18n_cj_m1xqbpyw80000gn/T/RackMultipart20151008-24531-1f7lkwr.jpg>, @original_filename="_MG_9847.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"_MG_9847.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007fbffb8132e8 @tempfile=#<Tempfile:/var/folders/dz/tf2gsysx18n_cj_m1xqbpyw80000gn/T/RackMultipart20151008-24531-1u4h5f2.jpg>, @original_filename="_MG_9857.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"_MG_9857.jpg\"\r\nContent-Type: image/jpeg\r\n">], "project"=>{"title"=>"Тестик", "desctitle"=>"Проектик", "description"=>"пупик", "teammember_ids"=>["6", ""]}, "commit"=>"Сохранить проект"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Teammember Load (0.2ms) SELECT "teammembers".* FROM "teammembers" WHERE "teammembers"."id" = $1 LIMIT 1 [["id", 6]]
(0.1ms) BEGIN
SQL (1.8ms) INSERT INTO "projects" ("title", "description", "desctitle", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["title", "Тестик"], ["description", "пупик"], ["desctitle", "Проектик"], ["created_at", "2015-10-08 14:17:11.018140"], ["updated_at", "2015-10-08 14:17:11.018140"]]
SQL (1.4ms) INSERT INTO "participations" ("teammember_id", "project_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["teammember_id", 6], ["project_id", 51], ["created_at", "2015-10-08 14:17:11.021601"], ["updated_at", "2015-10-08 14:17:11.021601"]]
(1.4ms) COMMIT
(0.1ms) BEGIN
SQL (3.4ms) INSERT INTO "projectphotos" ("image", "project_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["image", "_MG_9839.jpg"], ["project_id", 51], ["created_at", "2015-10-08 14:17:12.074996"], ["updated_at", "2015-10-08 14:17:12.074996"]]
(0.5ms) COMMIT
(0.1ms) BEGIN
SQL (0.4ms) INSERT INTO "projectphotos" ("image", "project_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["image", "_MG_9847.jpg"], ["project_id", 51], ["created_at", "2015-10-08 14:17:12.914800"], ["updated_at", "2015-10-08 14:17:12.914800"]]
(0.4ms) COMMIT
(0.1ms) BEGIN
SQL (0.4ms) INSERT INTO "projectphotos" ("image", "project_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["image", "_MG_9857.jpg"], ["project_id", 51], ["created_at", "2015-10-08 14:17:13.759695"], ["updated_at", "2015-10-08 14:17:13.759695"]]
(0.4ms) COMMIT
Redirected to http://localhost:9292/admin/projects
Completed 302 Found in 2780ms (ActiveRecord: 11.4ms)
恰到好處,被上傳的圖片等。
現在,生產服務器上的完全相同的操作來:
I, [2015-10-08T10:23:50.330774 #13367] INFO -- : Started POST "/admin/projects" for 89.169.175.47 at 2015-10-08 10:23:50 -0400
I, [2015-10-08T10:23:50.334229 #13367] INFO -- : Processing by Admin::ProjectsController#create as HTML
I, [2015-10-08T10:23:50.334437 #13367] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"2hx8xJdCrvkmwkfKGI4Y/gzu3bc/hPWNsrWgtNo/97kWFWKauYOrWh6v15mHQ/28sqaaAb08hEhHrkuvFjmxPw==", "projectphotos"=>[#<ActionDispatch::Http::UploadedFile:0x007f6d9006fc98 @tempfile=#<Tempfile:/tmp/RackMultipart20151008-13367-18ri23t.jpg>, @original_filename="_MG_9839.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"_MG_9839.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007f6d9006fc20 @tempfile=#<Tempfile:/tmp/RackMultipart20151008-13367-yrlhkm.jpg>, @original_filename="_MG_9847.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"_MG_9847.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007f6d9006fba8 @tempfile=#<Tempfile:/tmp/RackMultipart20151008-13367-1l2x4tu.jpg>, @original_filename="_MG_9857.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"_MG_9857.jpg\"\r\nContent-Type: image/jpeg\r\n">], "project"=>{"title"=>"Тестовый проект", "desctitle"=>"Тестик", "description"=>"Тестовый проект", "teammember_ids"=>[""]}, "commit"=>"Сохранить проект"}
D, [2015-10-08T10:23:50.337997 #13367] DEBUG -- : User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
D, [2015-10-08T10:23:50.343076 #13367] DEBUG -- : (0.1ms) BEGIN
D, [2015-10-08T10:23:50.346752 #13367] DEBUG -- : SQL (1.2ms) INSERT INTO "projects" ("title", "description", "desctitle", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["title", "Тестовый проект"], ["description", "Тестовый проект"], ["desctitle", "Тестик"], ["created_at", "2015-10-08 14:23:50.343540"], ["updated_at", "2015-10-08 14:23:50.343540"]]
D, [2015-10-08T10:23:50.348048 #13367] DEBUG -- : (0.7ms) COMMIT
D, [2015-10-08T10:23:50.349034 #13367] DEBUG -- : (0.2ms) BEGIN
D, [2015-10-08T10:23:50.373831 #13367] DEBUG -- : (0.3ms) COMMIT
D, [2015-10-08T10:23:50.374391 #13367] DEBUG -- : (0.2ms) BEGIN
D, [2015-10-08T10:23:50.384639 #13367] DEBUG -- : (0.2ms) COMMIT
D, [2015-10-08T10:23:50.385026 #13367] DEBUG -- : (0.2ms) BEGIN
D, [2015-10-08T10:23:50.392234 #13367] DEBUG -- : (0.2ms) COMMIT
I, [2015-10-08T10:23:50.393967 #13367] INFO -- : Redirected to http://46.101.161.208/admin/projects
I, [2015-10-08T10:23:50.394322 #13367] INFO -- : Completed 302 Found in 60ms (ActiveRecord: 6.2ms)
圖像在params哈希表,但不插入到數據庫中。有人能讓我指出正確的方向嗎?
這裏是我的projects_controller.rb:
def update
if @project.update(project_params)
if params[:projectphotos]
params[:projectphotos].each { |image| @project.projectphotos.create(image: image) }
end
redirect_to admin_projects_path
flash[:success] = "Updated"
end
end
def edit
end
def show
end
def create
@project = Project.new(project_params)
if @project.save
if params[:projectphotos]
params[:projectphotos].each { |image| @project.projectphotos.create(image: image) }
end
redirect_to admin_projects_path
flash[:success] = 'Created'
else
flash[:alert] = 'Something went wrong'
render 'new'
end
end
這完全相同的代碼已經在生產AFO工作一段時間,但我認爲在某些時候,我說的ImageMagick後調整其大小停止工作。我切換到MiniMagick,而在其他項目調整大小和圖像上傳與MiniMagick運作良好,在這裏我有這個問題的生產。說實話,這就是爲什麼我不相信,這個問題是由MiniMagick引起的,只是想分享這些信息。
更新: 按照要求,這裏是我上傳的代碼:
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Create different versions of your uploaded files:
# version :thumb do
# process :resize_to_fit => [50, 50]
# end
version :thumb_next do
process :resize_to_fill => [600, 460]
end
version :main_image do
process :resize_to_fill => [1170, 700]
end
version :thumb_small do
process :resize_to_fit => [50,50]
end
version :thumb_medium do
process :resize_to_fit => [350,350]
end
end
更新2: 這是獲得更離譜的是,我添加了一些簡單的輸出調試我的生產代碼:
projects_controller.rb
def update
if @project.update(project_params)
if params[:projectphotos]
p "inside params"
params[:projectphotos].each do |image|
p image
p "inside of each image param"
if @project.projectphotos.create(image: image)
p "created image"
end
end
end
redirect_to admin_projects_path
flash[:success] = "Updated"
end
end
隨着該更新,我得到THI s on production:
[email protected]:~$ cat apps/furnitureapp/current/log/puma.error.log
=== puma startup: 2015-10-12 05:23:35 -0400 ===
* Inherited unix:///home/deploy/apps/furnitureapp/shared/tmp/sockets/furnitureapp-puma.sock
"inside params"
#<ActionDispatch::Http::UploadedFile:0x007f6e08304828 @tempfile=#<Tempfile:/tmp/RackMultipart20151012-26945-1wzj8kl.jpg>, @original_filename="American-Psycho-blood.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"American-Psycho-blood.jpg\"\r\nContent-Type: image/jpeg\r\n">
"inside of each image param"
"created image"
#<ActionDispatch::Http::UploadedFile:0x007f6e083047b0 @tempfile=#<Tempfile:/tmp/RackMultipart20151012-26945-ahjgw2.jpg>, @original_filename="i-love-sales.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"projectphotos[]\"; filename=\"i-love-sales.jpg\"\r\nContent-Type: image/jpeg\r\n">
"inside of each image param"
"created image"
但仍然沒有圖像,仍然沒有INSERT sql-queries! Projectphoto.all顯示沒有條目,但它顯然應該創建一個圖像。
有人通過重新啓動服務器解決了問題。 http://stackoverflow.com/a/23819632/1970061 –
對不起,但這沒有幫助。我重啓服務器,puma,nginx,通過「restart」和「stop&start」。這仍然是我最近的結果 - http://take.ms/RxSXq(無變化) 奇怪的事情 - 我沒有得到任何錯誤...這就是爲什麼我不知道從哪裏開始挖掘 – mohnstrudel
好的,那麼還可以添加你的上傳代碼 – illusionist