Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 使每个帐户都有一个单独的S3存储桶,用于使用Silke的附件_Ruby_Shrine - Fatal编程技术网

Ruby 使每个帐户都有一个单独的S3存储桶,用于使用Silke的附件

Ruby 使每个帐户都有一个单独的S3存储桶,用于使用Silke的附件,ruby,shrine,Ruby,Shrine,在我们的Ruby中,我希望每个帐户都有一个单独的S3存储桶用于其附件。我还希望bucket名称可以从帐户的属性派生: Account(id: 1, username: "johnny") # uses the "1-johnny" bucket Account(id: 2, username: "peter") # uses the "2-peter" bucket # ... 这样的事情在中国可以做吗?是的。首先,使用default\u storage插件动态分配存储名称: Shrine.

在我们的Ruby中,我希望每个帐户都有一个单独的S3存储桶用于其附件。我还希望bucket名称可以从帐户的属性派生:

Account(id: 1, username: "johnny") # uses the "1-johnny" bucket
Account(id: 2, username: "peter")  # uses the "2-peter" bucket
# ...

这样的事情在中国可以做吗?

是的。首先,使用
default\u storage
插件动态分配存储名称:

Shrine.plugin :default_storage, store: ->(record, name) do
  "store_#{record.id}_#{record.username}"
end

# store_1_johnny
# store_2_peter
接下来,使用
dynamic_storage
插件根据标识符动态实例化S3存储:

Shrine.plugin :dynamic_storage

Shrine.storage /store_(\d+)_(\w+)/ do |match|
  bucket_name = "#{match[1]}_#{match[2]}"
  Shrine::Storage::S3.new(bucket: bucket_name, **s3_options)
end

# 1-johnny
# 2-peter

您是否知道默认设置?。这可能是一个问题,当你得到更多的用户…感谢你注意到,我没有意识到这一点。这仍然适用于用户数量有限的情况(例如,活动经理)。谷歌云存储对存储桶的总数没有限制,但令人失望的是,可能的名称没有按帐户确定范围。例如,如果您创建一个名为“test”的bucket,那么我无法创建另一个名为“test”的bucket。换句话说,这些名字在全世界都必须是独一无二的。