Don't I feel stupid.
I just posted to the mailing list about a question that was in the getting started! AH!


I was rushing through and everything I was seeing was about image manipulation so I wasn't paying attention and the very last code snippet was the one I needed.

I should have watched the Railcast first. It was exactly what I needed in the way I needed it.

@user.avatar.url

Assuming that the model is user, the has_file_attachment is avatar then that is how you get the URL.

has_attached_file :data,
    :path => ":rails_root/public/system/:attachment/:id/:basename.:extension",
    :url => "/system/:attachment/:id/:basename.:extension"

It seems to be important that the URL is the public version of the path. This may be due to that I'm using the same name for my attachment as the model itself.


And here's some linkage:
Railscast: PaperClip
For attaching files, use Paperclip
Paperclip Tips and Updates
Active Scaffold with Paperclip
Multiple Attachments with Validations In Rails with Paperclip

If you read each of those with relative care it should answer all questions you might have.

Current (Feb 2010) Documentation as opposed to outdated documentation found elsewhere.

By AJ ONeal

If you loved this and want more like it, sign up!


Did I make your day?
Buy me a coffeeBuy me a coffee  

(you can learn about the bigger picture I'm working towards on my patreon page )