Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rails 3 library that uploads all static assets to aliyun oss with a unique id encoded into the path

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 README_EN.textile
Octocat-spinner-32 asset_oss.gemspec
README.md

Asset OSS - 上传Rails项目静态文件到Aliyun OSS

关于

基于asset_id,aset_sync也许是更好的选择

一个简单的上传Rails assets目录里静态文件到Aliyun OSS工具

使用和配置

添加gem "asset_oss"到你的Gemfile

修改config/environments/production.rb文件, config.action_controller.asset_host = "http://my_live_bucket.oss.aliyuncs.com"

新建一个config/asset_oss.yml文件

production:
  host: 'oss.aliyuncs.com'
  access_key_id: 'MY_ACCESS_KEY'
  secret_access_key: 'MY_ACCESS_SECRET'
  bucket: "my_live_bucket"

创建rake任务, lib/tasks/asset_oss.rake

namespace :asset do
  namespace :oss do

    desc "uploads the current assets to aliyun oss with stamped ids"
    task :upload do
      AssetOSS::Asset.asset_paths += ['assets'] # Configure additional asset paths
      AssetOSS::OSS.upload
    end

  end
end

其它

也许可以通过修改Rails config.assets.prefix实现缓存过期,记得prefix要是assets开头,同时修改AssetOSS::Asset.asset_paths

Something went wrong with that request. Please try again.