简体   繁体   English

在Rails中使用用户定义的资产服务器

[英]Use user-defined asset servers in Rails

I'm building an application in Rails where sets of images can be created, ie the user uploads a file of image names and specifies a path where those images can be found on the web. 我正在Rails中构建一个可创建图像集的应用程序,即用户上传图像名称文件并指定可在网上找到这些图像的路径。

So, for example, the image file contains: 因此,例如,图像文件包含:

image1.jpg
image2.jpg

and the path is specified as http://www.user1-server.com/ . 并将路径指定为http://www.user1-server.com/

Another user could load his own file of image names, but specify another server: http://www.user2-server.com/ or even http://my-fancy-server.com . 另一个用户可以加载自己的映像名称文件,但可以指定另一个服务器: http://www.user2-server.com/ : http://www.user2-server.com/甚至http://my-fancy-server.com

Is there any way to use the AssetTagHelper functionality of Rails to help me generate the image tags? 有什么方法可以使用Rails的AssetTagHelper功能来帮助我生成图像标签吗?

So, if I'm in the context of user 1, eg /users/1/images/1 , and use: 因此,如果我处于用户1的上下文中,例如/users/1/images/1 ,则使用:

image_tag("1.jpg")

it should deliver http://www.user1-server.com/images/1.jpg , but for /users/2/images/1 it should return http://www.user2-server.com/images/1.jpg or http://my-fancy-server.com/images/1.jpg . 它应该提供http://www.user1-server.com/images/1.jpg ,但对于/users/2/images/1它应该返回http://www.user2-server.com/images/1.jpghttp://my-fancy-server.com/images/1.jpg

I don't think you can change asset host in Rails on the fly like that. 我不认为您可以像这样在Rails中即时更改资产托管。 Rails is smart enough to not set or override the host passed into an image tag, though. 不过,Rails足够聪明,不会设置或覆盖传递给image标签的主机。 Maybe just write a helper method or something to pass the correct host in? 也许只是编写一个帮助程序方法或一些东西来传递正确的主机?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM