简体   繁体   中英

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.

So, for example, the image file contains:

image1.jpg
image2.jpg

and the path is specified as 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 .

Is there any way to use the AssetTagHelper functionality of Rails to help me generate the image tags?

So, if I'm in the context of user 1, eg /users/1/images/1 , and use:

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 .

I don't think you can change asset host in Rails on the fly like that. Rails is smart enough to not set or override the host passed into an image tag, though. Maybe just write a helper method or something to pass the correct host in?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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