您好,我在 Rails 中上传文件时遇到此问题。我已经设置了蜻蜓,它在管理方面运行良好,但是然后我尝试上传我的文件(pdf或doc)它为我的文件属性传递了空参数
好的,这里是表格:
= form_for @vacancy_application, url: {action: "create"}, html: {multipart: true, class: "block valid"} do |f|
%fieldset
%label{for: "vacancy_application_cv_uid"}= t("vacancy.form.cv")
= f.file_field :cv
= f.hidden_field :retained_cv
%fieldset
%label{for: "vacancy_application_mv_uid"}= t("vacancy.form.mv")
= f.file_field :mv
= f.hidden_field :retained_mv
%footer
%a.submit#submit_button{href: "#"}= t("vacancy.form.button_continue")
这是我的控制器:
def create
@vacancy_application = VacancyApplication.new(app_params)
respond_to do |format|
if @vacancy_application.save
format.html { redirect_to "/" }
format.json { render json: {link: "/"}, status: :created, location: nil }
else
format.html { render action: "vacancy_application" }
format.json { render json: @vacancy_application.errors, status: :unprocessable_entity }
end
end
end
在我的模型中:
class VacancyApplication < ActiveRecord::Base
belongs_to :vacancy
dragonfly_accessor :cv
dragonfly_accessor :mv
validates :cv, presence: true
alias_attribute :to_text, :title
end
但是当我尝试发送表单时,我得到的参数是这样的:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"XliKgSIONsDQ4rea1OSk+EuoZHUXWOWUjYsy71vs/Rs=", "vacancy_application"=>{"retained_cv"=>"", "retained_mv"=>""}, "node_id"=>"35", "locale"=>"lv"}
我缺少两个文件上传参数。我不明白我做错了什么。
是蜻蜓吗?蜻蜓甚至支持doc或pdf文件上传吗?请帮帮我 :)
PS我在4.0.4 Rails版本和最新的蜻蜓版本