我有带附件字段的应用程序表,这是由carrierwave上传的文件。我使用的是SQLLite。申请表格提交后,在#create
中@application = Application.new(application_params)
@application包含附件为nil。 有趣的是, params [:attachment]也是nil但是params [:application] [:attachment] =' valid / path / of / file'和application_params也相同/有效/路径/ /文件'。
因此无法保存@application,因为没有附件我无法保存。它突然开始了,我无法弄清楚。任何人都可以请指教。 TIA。 #create action upto save:
def create
@application = Application.find_by_user_id_and_type_id(params[:application][:user_id], params[:application][:type_id])
if params[:application][:attachment].nil? || params[:application][:attachment].blank?
flash[:notice] = "You have to add an attachment of type - .doc/.docx/.pdf/.txt/.rtf."
end
if @application.nil?
@application = Application.new(application_params)
if @application.save
这是来自提交的浏览器输出。
{"utf8"=>"✓","authenticity_token"=>"egFav9RYAOXJQ==","application{"user_=>"109", "type_id"=>"4", "years_of_experience"=>"", "attachment"=>"/uploads/data_attachment/attachment/93/Steps_to_be_done.docx", "message"=>""},"commit"=>"Submit"}
现在我今天早上做了一个小黑客,强迫'它可以工作一段时间。不确定,为什么它现在工作而不是现在。
def application_params
params.require(:application).permit(:user_id, :type_id, :message, :years_of_experience, :attachment)
if params[:attachment].nil?
params.fetch(:application).permit(:user_id, :type_id, :message, :years_of_experience, :attachment)
end