我试图在我的模型的更新方法中完成一些功能。但是,我收到以下错误,这似乎是由于rails 4中引入的强参数约定。
Upload.rb (Model)
Update method
def update
mode = nil
market = nil
case @upload.task_id
when 1
mode = "channel"
market = nil
when 2
mode = "national"
market = "national"
when 3
mode = "regional"
market = "t"
when 4
mode = "regional"
market = "c"
when 5
mode = "regional"
market = "e"
when 6
mode = "regional"
market = "v"
else
puts"Error!! Received invalid task.id to parse"
end
options = Hash[:file_path =>Upload.find(params[:id]).f_path , :mode =>"#{mode}", :market=>"#{market}"]
puts "options= #{options.inspect}"
@cp = CsvParser.new(options)
if @upload.update(upload_params)
redirect_to @upload, notice: 'Upload was successfully updated.'
else
render action: 'edit'
end
end
# Only allow a trusted parameter "white list" through.
def upload_params
params.require(:upload).permit(:sourcedata, :task_id, :status, :file_path, :options, :mode, :market)
end
错误
ActionController::ParameterMissing - param not found: upload:
actionpack (4.0.0) lib/action_controller/metal/strong_parameters.rb:173:in `require'
我在上面的代码中做错了什么。为什么我不能发送我的参数。我应该调整什么来使这项工作。我对强大的参数感到有些困惑,如果有人有任何建议,我会很感激。在互联网上搜索我得到了无关的东西,所以想知道是否有人可以提供帮助。
谢谢,
答案 0 :(得分:0)
ActionController::ParameterMissing
基本上是说当前请求不符合params.require(:upload)
,即params [:upload]不存在。
问题似乎不在您的更新操作上,而是在您的编辑操作上,或者在您构建表单的方式内的编辑视图中。您应该发布您的def edit
代码和edit.html.erb或构建更新表单的任何视图,以进一步解决此问题。