出于某种原因,我的查询文件上传ajax表单出现以下错误:
ActionController::ParameterMissing (param not found: profile):
app/controllers/profiles_controller.rb:146:in `profile_params'
app/controllers/profiles_controller.rb:52:in `create'
以下是发送的参数:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"fdsahKJAHLSJFJAHFAS323FDSGF4="}
因此,由于某种原因,未发送配置文件参数。这是我的表格:
<%= form_for @profile, :html => { :class => "clearfix", :id => "the_form"},
remote: true do |f| %>
<%= f.file_field :pic, name: 'profile[pic]', :class => "field file-field",
:id => "file", :multiple => true %>
<% end %>
以下是我的强大参数:
def profile_params
params.require(:profile).permit(:title, :pic, :category, :description,
:state, :zip_code, :rate)
end
以下是加载表单的配置文件#new action:
def new
@profile = Profile.new
@skills = Skill.all.collect {|skill| skill.label} #this is for something else on the page
end
此外,这是获取表单的咖啡脚本文件。由于表单是通过ajax呈现的,我需要使用ajaxcomplete方法。
jQuery ->
$(document).ajaxComplete ->
$('#the_form').fileupload
dataType: "script"
add: (e, data) ->
types = /(\.|\/)(gif|jpe?g|png)$/i
file = data.files[0]
if types.test(file.type) || types.test(file.name)
data.submit()
else
alert("#{file.name} is not a gif, jpeg, or png image file")
done: (e, data) ->
$('#finish-text').html "Upload finished"
我知道咖啡脚本有效,因为它正在使用另一种形式。
为什么不发送个人资料参数?
答案 0 :(得分:2)
添加:multipart =&gt;如果您的表单中有文件上传字段,则表单中为
例如:
<%= form_for @profile, :html => { :class => "clearfix", :id => "the_form", :multipart => true}, remote: true do |f| %>