Sha256: df956fc61a1eea1f67733e377c1d46e56dc42f132cb438763c63b2507e0b3840

Contents?: true

Size: 900 Bytes

Versions: 11

Compression:

Stored size: 900 Bytes

Contents

class ImagesController < ApplicationController
  respond_to :html, :json

  def index
    @images = Image.scoped

    respond_with @images do |format|
      format.json { render :json => json_images(@images), :layout => false }
    end
  end

  def create
    @image = Image.new(params[:image])

    if @image.save
      render :text => view_context.image_tag(resize_image(@image, 300, 250).url, :alt => '')
    else
      render :json => @image.errors
    end
  end

private

  def json_images(images)
    json_images = []

    images.each do |image|
      json_images << {
        :thumb => resize_image(image, 120, 100).url,
        :image => resize_image(image, 300, 250).url
      }
    end

    json_images
  end

  def resize_image(image, width = 100, height = 100, gravity = :c)
    image.image.process(:resize_and_crop, :width => width, :height => height, :gravity => gravity.to_s)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
imperavi-rails-0.0.12.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.11.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.10.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.9.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.8.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.7.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.6.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.5.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.4.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.3.beta spec/dummy/app/controllers/images_controller.rb
imperavi-rails-0.0.2.beta spec/dummy/app/controllers/images_controller.rb