dendomenko
dendomenko

Reputation: 446

Get paperclip full url in model

I publish some data in redis after saving my model and I need send full url of attachment to Redis, but I'm stuck to get rails root url with port or full attachment url.
How I can get full url of paperclip attachments or get rails app root url in model file?

Upvotes: 0

Views: 278

Answers (2)

Saurav Prakash
Saurav Prakash

Reputation: 1247

The use case is also in web sockets. Use #{request.host} or #{request.port} or #{request.protocol} or #{request.params} to get the necessary request information. @Danil answer is the right string interpolation for the question.

Upvotes: 0

Danil Speransky
Danil Speransky

Reputation: 30453

Models don't know how you deploy the application. However controllers do via request object:

"#{request.protocol}#{request.host}"

You could pass it to the model level, however it breaks the abstraction badly.

I would consider changing the design.

Upvotes: 1

Related Questions