我正在将我的回形针附件上传到s3,因为在我的模型中我正在使用这样的雾凭证......问题是我需要为不同的env设置不同的存储桶名称,方法是在模型中定义为每个指定的存储桶环境,那我可以在哪里定义它?
has_attached_file :news_logo,
:storage => :fog,
:fog_credentials => "#{Rails.root}/config/s3.yml",
:fog_directory => "s3-bucket-name"
配置/ s3.yml
development:
provider: AWS
aws_access_key_id: xyz
aws_secret_access_key: xyz
path_style: true
答案 0 :(得分:3)
您可以使用 Rails.env 来自定义您的存储桶名称,例如:
has_attached_file :news_logo,
:storage => :fog,
:fog_credentials => "#{Rails.root}/config/s3.yml",
:fog_directory => "s3-bucket-name-#{Rails.env}"
您还可以执行以下操作:
has_attached_file :news_logo,
:storage => :fog,
:fog_credentials => "#{Rails.root}/config/s3.yml",
:fog_directory => (case Rails.env
when 'production' then 'my-production-bucket'
when 'testing' then 'testing-bucket'
else 'this-is-development-bucket';
end)
答案 1 :(得分:0)
修改代码如下
function increaseEachValueBy({arrays, value}={}){
arrays.forEach((array, index, original)=> { original[index] = array.map(item => item+ value)})
}
let TwoDimensionArray = [[4,6,4],[4,9,9]]
increaseEachValueBy({ arrays: TwoDimensionArray , value:10})
console.log(TwoDimensionArray)
并在常量文件中定义存储桶名称。
config / initializers / constants.rb
const ViewModel = function() {
this.otherComputed = ko.computed(() => true);
this.computedUnderTest = ko.computed(() => this.otherComputed());
};
const vm = new ViewModel();
function expect(expected) {
console.log(vm.computedUnderTest() === expected);
}
// Init
expect(true);
// Stub dependent computed
vm.otherComputed = () => false;
// Computed no longer receives updates :(
expect(false);
// Can we force re-evaluation?
// vm.computedUnderTest.forceReEval()