2013-05-21 58 views
1

我想配置回形針與openshift一起使用它,但我無法做到這一點,任何建議嗎?與openshift一起使用的回形針配置

has_attached_file :photo, 
       :styles => { 
       :thumb=> "100x100#", 
       :small => "400x400>" 
      }, 
      :url => "/assets/users_folder/:id/:style/:id.:extension", 
      :path => ENV['OPENSHIFT_DATA_DIR']+"public/assets/users_folder/:id/:style/:id.:extension" 

回答

2

最後我們這樣做:

:url => "/assets/:id.:extension",<br> 
:path => ":rails_root/public/assets/:id.:extension" 

和openshif的部署文件(/.openshift/action_hooks/deploy):

STORED_ASSETS="${OPENSHIFT_DATA_DIR}/assets" 
LIVE_ASSETS="${OPENSHIFT_REPO_DIR}/public/assets" 

\# Ensure our stored assets directory exists 
if [ ! -d "${STORED_ASSETS}" ]; then 
    echo " Creating permanent assets directory" 
    mkdir "${STORED_ASSETS}" 
fi 

\# Create symlink to stored assets unless we're uploading our own assets 
if [ -d "${LIVE_ASSETS}" ]; then 
    echo " WARNING: Assets included in git repository, not using stored assets" 
else 
    echo " Restoring stored assets" 
    ln -sf "${STORED_ASSETS}" "${LIVE_ASSETS}" 
fi 

這樣,我們創建了一個鏈接我們的數據文件夾(OPENSHIFT_DATA_DIR)永遠不會被git推送。

+0

我曾嘗試用自己的方式和它仍然被刪除。你能解釋一下這個嗎? – logesh

0

基於由阿爾弗雷多在您的模型,以便爲不同型號不同的風格,以節省了答案 - 類似回形針的默認:

has_attached_file :image, 
       :url => "/uploads/:class/:attachment/:id/:style_:filename", 
       :path => ":rails_root/public/uploads/:class/:attachment/:id/:style_:filename" 

快速的解釋:

  • :RAILS_ROOT將是你的導軌根
  • :類將圖像的名稱模型(複數)
  • :附件將是字段的名稱(複數形式)
  • :ID將模型的電流id
  • :STYLE_將是您爲圖像定義的樣式(如拇指,原等)
  • :文件名會是最後的文件名的文件夾 在(rails_root是您的rails根目錄,類通常是您的模型的名稱,附件是字段的名稱,id是模型的id,style是您定義的樣式 - thumb等 - 而filename是文件名圖片)

請注意/ assets/to/uploads /文件夾的更改。根據您的git配置,資產文件夾可能會被刪除。

最後,在/.openshift/action_hooks/deploy文件的末尾:

STORED_ASSETS="${OPENSHIFT_DATA_DIR}/uploads" LIVE_ASSETS="${OPENSHIFT_REPO_DIR}/public/uploads" 

# Ensure our stored assets directory exists 
if [ ! -d "${STORED_ASSETS}" ]; then 
echo " Creating permanent assets directory" 
mkdir "${STORED_ASSETS}" 
fi 

# Create symlink to stored assets unless we're uploading our own assets 
if [ -d "${LIVE_ASSETS}" ]; then 
echo " WARNING: Assets included in git repository, not using stored  assets" 
else 
echo " Restoring stored assets" 
ln -sf "${STORED_ASSETS}" "${LIVE_ASSETS}" 
fi