在我的应用程序中,我使用carrierwave
进行图像上传。
我的CampaignsController
是平常的create action
def create
@campaign = Campaign.new(campaign_params)
respond_to do |format|
if @campaign.save
format.html { redirect_to @campaign, notice: 'Campaign was successfully created.' }
format.json { render :show, status: :created, location: @campaign }
else
format.html { render :new }
format.json { render json: @campaign.errors, status: :unprocessable_entity }
end
end
end
在development
中一切正常,但是在提交/保存后production
中一切正常。
我的意思是:
在development
中,提交表单后,保存到localhost:3000/campaigns/38
,我的表单是:action="campaigns/38"
但
在生产中,提交表单后,保存后,它会转到example.com/campaigns/38
,而不是转到example.com/campaigns/campaigns/38
,而我的表单将变为:action="campaigns/campaigns/38"
。
您会看到URL中有额外的campaigns
,但我不确定为什么。
这是我的routes.rb
:
Rails.application.routes.draw do
resources :campaigns do
get 'changes', to: 'campaigns#deactivate_activate'
put 'changes', to: 'campaigns#deactivate_activate'
end
# match '*any' => 'application#options', :via => [:options]
end
这是我的ImageUploader
:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :large do
resize_to_limit(600, 600)
end
我的Campaign
模型:
class Campaign < ApplicationRecord
mount_uploader :image, ImageUploader
这是我的应用程序版本:
ruby "2.3.1"
gem 'rails', '~> 5.1.6'
carrierwave (1.3.1)
我一直在用不同的东西进行测试,以查看到底是什么问题。我使用simple_form_for
,form_for
进行了测试,甚至删除了form
的一部分。
只要= f.file_field :image
不存在,一切都会起作用。当我从= f.file_field :image
中删除form
时,在所有ENV中一切正常,但是当我重新添加它时,它比Production
时有这种奇怪的行为。
感谢您的任何帮助,并在此先感谢您!