Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7773897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:14:33+00:00 2026-06-01T17:14:33+00:00

I am using paperclip to save images. Everything works fine and I am able

  • 0

I am using paperclip to save images. Everything works fine and I am able to access the item’s url with @item.image.url.

class Item
 has_attached_file :image, :styles => {
      :original => ['1920x1680>', :jpg],
      :small => ['100x100>', :jpg],
      :medium => ['250x250>', :jpg],
      :large => ['500x500>', :jpg]
    }
end

This is console:

> Item.last.image.url(:small)
=> "/system/images/items/1/small/chanel.jpg?1334005208" 

This is straightforward and easy if I am templating HAML or ERB from the server and serving up the page to the user like this. items/show.html.haml:

.item
  .item-image
    = image_tag @item.image.url(:small)

However, with backbone.js, I am unable to construct the URL because I do not have the paperclip helpers in context. Essentially, I am sending the following attributes of the image to the page in json form.

#<Item:0x007fc97559b960> {
                    :id => 1,
    :image_content_type => "image/jpeg",
       :image_file_name => "chanel.jpg",
       :image_file_size => 28880,
      :image_updated_at => 2012-04-09 21:00:08 UTC
}

What is a ninja way to get the image.url included as an attribute on the item. How do I account for the style URLS? It would be nice to have an attribute like “image_small_url”, “image_normal_url”, etc predetermined and accessible. Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:14:34+00:00Added an answer on June 1, 2026 at 5:14 pm

    I’m using Jbuilder to build the JSON views for a project I’m working on, so my index view, for example looks like this:

    json.array!(@things) do |json, thing|
      json.id thing.id
      json.name thing.name
      json.description thing.description
      json.image_url thing.image.url
      json.thumb_url thing.image.url(:thumb)
    end
    

    That way in my Backbone template, I can just say thing.get('image_url') and thing.get('thumb_url').

    In brief, you’ll want to use something like Jbuilder, or manually override as_json in your model. Personally, I like taking care of this at the view level, which is what Jbuilder allows you to do easily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I storing images using paperclip + S3 has_attached_file :image, :whiny => false, :styles =>
I'm using paperclip by thoughtbot for attachments to models and everything works fine on
I'm saving an image upload using Paperclip in Rails, which is working fine. has_attached_file
I'm using rails and paperclip to save images, the usual way. When a record
Using Paperclip, I want to grab an image from a URL like this: require
I'm using Paperclip to save pictures in my Rails application: User model: class User
I've added 2000 pictures to my images table and I'm using the Paperclip plugin
I am using paperclip to save photos to my users' profiles. Rails is saving
I'm using Ruby 1.9 and Rails 2.3.4 with Paperclip gem to save attachments. and
I am using swfUpload plugin with paperclip which use flash to upload images but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.