Rails - building an absolute url in a model's virtual attribute without url helper

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-04-23T00:10:03Z Indexed on 2010/04/23 0:13 UTC
Read the original article Hit count: 276

Filed under:
|
|

I have a model that has paperclip attachments.

The model might be used in multiple rails apps

I need to return a full (non-relative) url to the attachment as part of a JSON API being consumed elsewhere.

I'd like to abstract the paperclip aspect and have a simple virtual attribute like this:

  def thumbnail_url
    self.photo.url(:thumb)
  end

This however only gives me the relative path. Since it's in the model I can't use the URL helper methods, right?

What would be a good approach to prepending the application root url since I don't have helper support? I would like to avoid hardcoding something or adding code to the controller method that assembles my JSON.

Thank you

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about model