我正在尝试配置回形针以将其与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"
答案 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"
快速解释:
注意/ 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