當您在程式中提供小人頭圖像上傳功能時,搭配Vlad the Deployer八成會出問題,因為Vlad the Deployer會從SVN下載新的版本,並把舊版本整個換掉,亦即使用者的個人圖像統統會消失。
為解決這問題,我們可以善用Vlad the Deployer的語法,首先要做的就是把原先上傳到Rails public目錄的圖檔整個搬移到Web server的目錄下:
mv /your_rails_app/public/user /var/www/user接著修改該目錄的權限:
sudo chmod -R mongrel:mongrel /var/www/user於是,我們可以在Vlad the Deployer的設定檔中,增加一個新的Remote task,負責幾件事情:
- 砍掉空的圖像目錄
- 做symbolic link連到/var/www/user
請在您的deploy.rb檔案中,加入以下語法:
namespace :vlad do
def sudo(command)
run [sudo_cmd, sudo_flags, command].join(' ')
end
desc "Setup user photos."
remote_task :setup_photo do
user_path = "#{current_path}/public/user"
sudo "rm -r #{user_path}"
sudo "ln -s /var/www/user #{user_path}"
end
end這個setup_photo要做的就是,每當遠端程式更新完畢之後,處理一些圖檔目錄相關的動作,於是往後更新版本,都可以保留使用者上傳的所有個人圖像。
