我有一个非常令人沮丧的时间来上传一些图片。它们显然是作为机架/多部分上传的,但我迭代参数哈希的方式一定会导致问题。我真的需要一些帮助,这样我就可以停止拔头发了。
所以我有一个看起来像这样的参数哈希:
Parameters: {"commit"=>"Submit", "sighting_report"=>[{"number_seen"=>"1", "picture"=>#<File:/var/folders/IX/IXXrbzpCHkq68OuyY-yoI++++TI/-Tmp-/RackMultipart.85991.5>, "species_id"=>"2"}], "authenticity_token"=>"u0eN5MAfvGWtfEzrqBt4qfrL54VJ9SGX0jFLZCJ8iRM=", "sighting"=>{"sighting_date(2i)"=>"6", "name"=>"", "sighting_date(3i)"=>"5", "county"=>"0", "notes"=>"", "location"=>"", "sighting_date(1i)"=>"2010", "email"=>""}}
我的表格可以有多个目击报告,每个目击报告中有多张图片。这是我的控制器代码:
def create_multiple
@report = Report.new
@report.name = params[:sighting]["name"]
@report.sighting_date = Date.civil(params[:sighting][:"sighting_date(1i)"].to_i, params[:sighting][:"sighting_date(2i)"].to_i, params[:sighting][:"sighting_date(3i)"].to_i)
@report.county_id = params[:sighting][:county]
@report.location = params[:sighting][:location]
@report.notes = params[:sighting][:notes]
@report.email = params[:sighting][:email]
@report.save!
@report.reload
for sr in params[:sighting_report] do
sighting = SightingReport.new
sighting.report_id = @report.id
sighting.species_id = sr[:species_id]
sighting.number_seen = sr[:number_seen]
sighting.save
if sr[:picture]
sighting.reload
for pic in sr[:picture] do
p = SpeciesPic.new
p.uploaded_picture = pic
p.species_id = sighting.species_id
p.report_id = @report.id
p.save!
end
end
end
redirect_to :action => 'new_multiple'
end
我似乎无法访问图片数据本身,但可以继续访问一些字符串。这不是文件名,而是转义字符的一些奇怪的东西。我可以做些什么来访问实际数据?