Tuesday, September 25, 2007

Tutorial: Fixing file_column's permissions

I came across a problem with file_column because it didn't update the permissions of the files and folders where you'd upload.

They'd stay at 600. I'd come across a routing error when trying to download files.

In the file_column.rb I edited the move_from method to look like this:

def move_from(local_dir, just_uploaded)
# create a directory named after the primary key, first
unless File.exists?(@dir)
FileUtils.mkdir(@dir)
#sets the permissions just in case it hasn't been set.
FileUtils.chmod_R 0755, @dir
end

# move the temporary files over
FileUtils.cp Dir.glob(File.join(local_dir, "*")), @dir

@just_uploaded = just_uploaded

# remove all old files in the directory
FileUtils.rm(Dir.glob(File.join(@dir, "*")).reject! {
|e| File.exists?(File.join(local_dir, File.basename(e)))
})

end


Since posting this, we've moved to attachment_fu. It's a lot nicer, but has a steeper learning curve. If you're learning on how to attach files, file_column is fine.

No comments: