title: Using different style for paperclip image in Rails while rendering in json
body: <p>I have a model which has an image field managed by paperclip:</p>
  
  <pre><code>class Meal &lt; ActiveRecord::Base
    has_attached_file :image, :default_url =&gt; "/images/normal/missing.png",
                  :styles =&gt; { :medium =&gt; "612x612", :small =&gt; "300x300" },
                  :path =&gt; ":rails_root/public/system/:attachment/:id/:style/:filename",
                  :url =&gt; "/system/:attachment/:id/:style/:filename"
  </code></pre>
  
  <p>I can access the different sizes like this:</p>
  
  <pre><code>    meals.each do |n|
        n.image.url(:small) # gives url for small images
        puts n.image.url # returns url for original images, I want this to return small for this function
      end
  </code></pre>
  
  <p>I am rendering the meals in JSON using <code>render :json</code>.</p>
  
  <p>My question is, how can I pass the small image URLs into my meals variable (in my controller below)? I want to be able to return small image URLs as I tried doing above, except return it when my response renders (see below).</p>
  
  <p>UPDATE:</p>
  
  <p>In my controller:</p>
  
  <pre><code>def view_patient
    response = Response.new
    this_doctor = Doctor.find_by_remember_token(Doctor.digest(auth_params["remember_token"]))
    if this_doctor
      this_patient = this_doctor.users.find_by_id(params[:id])
        if this_patient
          meals = this_patient.meals
          #
          # Here should be code on how to set the meals.image.url to small
          glucoses = this_patient.glucoses
          response.data = { :patient =&gt; this_patient,  :meals =&gt; meals }
          response.code = true
        else
          response.error = "Could not find patient"
          response.code = false
        end
    else
      response.error = "Please Login"
      response.code = false
    end
    render :json =&gt; response.json
  end
  </code></pre>