From 74deb1e2c68aa16ab4bf04509f98d362eb37c212 Mon Sep 17 00:00:00 2001 From: Daniel Munn Date: Mon, 24 Sep 2012 12:47:19 +0100 Subject: [PATCH] Fix attempt 2 for issue #50 - this any better? --- app/models/dmsf_file.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 4b7fccd2..517a23c0 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -348,10 +348,10 @@ class DmsfFile < ActiveRecord::Base dochash = Hash[*docdata.scan(/(url|sample|modtime|type|size)=\/?([^\n\]]+)/).flatten] filename = dochash["url"] if !filename.nil? - dmsf_attrs = filename.split("_") + dmsf_attrs = filename.scan(/^([^\/]+\/[^_]+)_([\d]+)_(.*)$/) id_attribute = 0 - id_attribute = dmsf_attrs[dmsf_attrs.length - 2] if dmsf_attrs.length > 2 - next if dmsf_attrs[1].blank? + id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length > 0 + next if dmsf_attrs.length == 0 || id_attribute == 0 next unless results.select{|f| f.id.to_s == id_attribute}.empty? dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => id_attribute, :deleted => false).first