0
当提交表单时,它会传递这些参数。Ruby on Rails将窗体变量传递给控制器
Parameters:
{"utf8"=>"✓",
"_method"=>"copyfile",
"authenticity_token"=>"yM2v0dJysGuw7zRIhuhY7xHMywuDRjfBqzpJc0/LCqE=",
"redocument"=>{"odocument_id"=>"14"},
"commit"=>"Update Redocument",
"method"=>"copyfile",
"id"=>"66"}
我想参考在控制器内传递的参数odocument_id
。
在我的控制器,我有这个
def copyfile
@oldfile = Redocument.find(params[:id])
@newfile = Redocument.find(params[:id]).dup
@newfile.odocument_id = params[:odocument_id]
if @newfile.save!
dupfile(@oldfile.redocument.to_s, @newfile.redocument.to_s)
flash[:notice] = 'Record was successfully cloned.'
else
flash[:notice] = 'Record ERROR: Item can\'t be cloned.'
end
redirect_to(:back)
end
我把它成功地创建新的ID文件夹中的文件。但是,我将我的目录结构分类为odocument_id/redocument_id /。在调用函数dupfile来创建文件夹和副本之前,我无法获取odocument_id进行更新。当我看到@newfile上传到MySQL时,它会创建一个NULL值。
谢谢Dipil。这工作。我之前有过“确切”的路线,但必须有一个类型-o。有时候,我会重新调用@newfile等冗余调用来让事情顺利进行。 – kobaltz 2011-12-15 04:36:48