slhck
slhck

Reputation: 38701

Use user-defined asset servers in Rails

I'm building an application in Rails where sets of images can be created, i.e. 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, e.g. /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.

Upvotes: 0

Views: 198

Answers (1)

idlefingers
idlefingers

Reputation: 32047

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?

Upvotes: 1

Related Questions