用于openshift的Paperclip配置

时间:2013-05-21 20:12:48

标签: ruby image paperclip 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 个答案:

答案 0 :(得分: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推送删除。

答案 1 :(得分:0)

基于alfredo在您的模型中的答案,以便为不同的模型保存不同的样式 - 类似于Paperclip的默认值:

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

快速解释:

  • :rails_root将是您的rails root
  • :class将是您的图像模型的名称(复数)
  • :附件将是该字段的名称(复数)
  • :id将是模型的当前ID
  • :style_将是您为图像定义的样式(例如拇指,原创等)
  • :filename将是文件夹中的最终文件名 (rails_root是你的rails root,class通常是你模型的名字,attachment是字段的名字,id是模型的id,style是你定义的样式 - thumb etc - 和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