我試圖上傳一個Carrierwave的文件與窗體和控制器是分開的模型Carrierwave安裝。Carrierwave無法通過不同的控制器上傳模型的圖像
我的上傳器LogoUploader安裝在設置模型的:logo
屬性上。
class Setting < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
mount_uploader :logo, LogoUploader
end
遷移:
class AddLogoToSettings < ActiveRecord::Migration
def change
add_column :settings, :logo, :string
end
end
我有一個表格,在views/feedback/configure.html.erb
用於處理圖像通過FeedbackController
上傳:
<%= form_tag({:action => 'save_configuration'}, id: 'form-save') do %>
<div class="form-group">
<%= file_field_tag "settings[cac_hlogo]" %>
<%= image_tag(@cac_hlogo.logo.url) if @cac_hlogo.logo? %>
</div>
<div class="form-actions">
<%= submit_tag t('save').titlecase, class: 'btn btn-primary' %>
</div>
<% end %>
FeedbackController:
class FeedbackController < ApplicationController
def configure
@cac_hlogo = Setting.find_or_create_by(name: 'cac_hlogo')
end
def save_configuration
cac_hlogo = Setting.find_or_create_by(name: 'cac_hlogo')
cac_hlogo.logo = params[:settings][:cac_hlogo]
respond_to do |format|
if cac_hlogo.save
format.html { redirect_to configure_feedback_index_path, notice: 'Configuration Saved.' }
else
format.html { redirect_to root_path, notice: 'There was a problem saving configuration.'}
end
end
end
end
我允許:logo
屬性在SettingsController
更新:
class SettingsController < ApplicationController
before_action :authenticate_user!
load_and_authorize_resource
def setting_params
params.require(:setting).permit(:logo)
end
end
出於某種原因,該文件實際上從未上傳和我不知道爲什麼。我在表單中傳遞的參數看起來沒問題,但實際上沒有上傳任何參數。我錯過了什麼?注意:我正在使用本地存儲,並且我的所有其他Carrierwave上傳器在應用程序中工作正常。