parameterize folder names
This commit is contained in:
parent
1131c656d5
commit
d9607ea0c8
4 changed files with 20 additions and 3 deletions
|
@ -24,6 +24,7 @@ class Album < ActiveRecord::Base
|
|||
|
||||
def ensure_path
|
||||
self.path = self.title unless self.path
|
||||
self.path.parameterize
|
||||
end
|
||||
|
||||
def set_title
|
||||
|
|
|
@ -87,7 +87,7 @@ class Photo < ActiveRecord::Base
|
|||
def swf_uploaded_data=(data)
|
||||
data.content_type = MIME::Types.type_for(data.original_filename)
|
||||
self.title = data.original_filename
|
||||
self.path = self.album.path + "/" + data.original_filename
|
||||
self.path = self.album.path + "/" + data.original_filename.parameterize
|
||||
File.open(APP_CONFIG[:photos_path] + self.path, 'wb') { |f| f.write(data.read) }
|
||||
end
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")[RAILS_ENV].symbolize_keys
|
||||
#APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/settings.yml")[RAILS_ENV].symbolize_keys
|
||||
APP_CONFIG = YAML.load(ERB.new(File.read("#{RAILS_ROOT}/config/settings.yml")).result)[RAILS_ENV].symbolize_keys
|
||||
|
|
17
lib/scan.rb
17
lib/scan.rb
|
@ -1,10 +1,11 @@
|
|||
module ScanFiles
|
||||
require "find"
|
||||
|
||||
require "fileutils"
|
||||
|
||||
supported_files = ["jpeg", "jpg", "gif", "png"]
|
||||
|
||||
def self.FullScan
|
||||
puts "Scanning " + APP_CONFIG[:photos_path]
|
||||
prevalbum = ""
|
||||
dirs = Array.new
|
||||
Find.find( APP_CONFIG[:photos_path] ) { |path|
|
||||
|
@ -14,6 +15,20 @@ module ScanFiles
|
|||
if File.file?(path) && [".jpeg", ".jpg", ".gif", ".png"].include?( File.extname(path) )
|
||||
relpath = File.dirname( path ).sub(APP_CONFIG[:photos_path], '')
|
||||
relfile = path.sub(APP_CONFIG[:photos_path], '')
|
||||
puts relpath
|
||||
relpathdirs = relpath.split("/")
|
||||
relpathparam = ""
|
||||
relpathdirs.each{|d|
|
||||
relpathparam += d.parameterize + "/"
|
||||
}
|
||||
relpathparam = relpathparam.slice(0..relpathparam.length-2)
|
||||
if relpath != relpathparam
|
||||
puts APP_CONFIG[:photos_path] + relpath + " will now be moved to " + APP_CONFIG[:photos_path] + relpathparam
|
||||
FileUtils.mv APP_CONFIG[:photos_path] + relpath, APP_CONFIG[:photos_path] + relpathparam
|
||||
puts "reload!"
|
||||
self.FullScan
|
||||
return
|
||||
end
|
||||
album = Album.find_by_path( relpath )
|
||||
if prevalbum != relpath
|
||||
puts relpath
|
||||
|
|
Loading…
Reference in a new issue