【发布时间】:2014-01-20 18:06:19
【问题描述】:
由于某种原因,我的查询文件上传 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 操作:
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"
我知道咖啡脚本有效,因为它正在使用另一种形式。
为什么没有发送配置文件参数?
【问题讨论】:
标签: ruby-on-rails ajax jquery ruby-on-rails-4 jquery-file-upload