I have an Inventory.find(id) and it returns all the data I need including the icons uploaded
using paperclip. However, the result is returned like this after format.json
"icon_content_type": "image/jpeg",
"icon_file_name": "images_(2).jpeg",
"icon_file_size": 994,
"icon_updated_at": "2012-09-21T05:00:22Z",
how do I include the “icon.url” so it will say something like
"icon_content_type": "image/jpeg",
"icon_file_name": "images_(2).jpeg",
"icon_file_size": 994,
"icon_updated_at": "2012-09-21T05:00:22Z",
"icon_url":"http://s3.amazonaws.com/*********/icons/000/000/130/original/images_(2).jpeg?1348203622"
here is my model
has_attached_file :icon, :presence => false, :default_url => "/assets/logo.png"
validates_attachment :icon,
:content_type => { :content_type => ["image/jpg","image/png","image/jpeg"] },
:size => { :in => 0..50.kilobytes }
See doc, you can add whatever you need to the json:
For more complex situations, you’d rather use a json builder.