🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

seven1m-acts_as_photo

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seven1m-acts_as_photo

bundlerRubygems
Version
0.2.0
Version published
Maintainers
1
Created
Source

acts_as_photo

Uber simple Rails plugin giving a model a single attached photo per record. When a photo is saved to the model, sized photo files are placed in the specified path, based on the indicated sizes (see below).

Note: Only JPEG images are supported at this time.

Requirements

  • ImageMagick
  • MiniMagick (not RMagick)

Install

Add the following to your environment.rb Initializer block:

config.gem 'seven1m-acts_as_photo', :source => 'http://gems.github.com', :lib => 'acts_as_photo'

Then run "sudo rake gems:install" to install as a dependency.

Or, use the traditional plugin install method:

script/plugin install git://github.com/seven1m/acts_as_photo.git

Setup

In the model:

class Person < ActiveRecord::Base PHOTO_SIZES = { :tn => '32x32', :small => '75x75', :medium => '150x150', :large => '400x400' } acts_as_photo Rails.root + 'db/photos/people', PHOTO_SIZES end

In your controller(s), you need an action that calls send_photo(obj), with "obj" being an instance of the record with the photo.

There are several ways to do this, the simplest of which may be:

class PeopleController < ApplicationController
  # url looks like "/people/1/photo" and "/people/1/photo?size=small"
  def photo
    @person = Person.find params[:id]
    send_photo @person
  end
end

You'll also need a member action in your routes.rb:

map.resources :people, :member => {:photo => :get}

Prettier URLs

For an example of using a singular resource "Photo" for several resources, check out the OneBody project:

  • routes.rb
  • photos_controller.rb

Usage

person.photo = file_like_object # form submission, File.open, etc.
# or
person.photo = 'http://example.com/tim.jpg'

person.rotate_photo('-90') # degrees

person.has_photo?
# => true

person.photo_path
# => 'db/photos/123.jpg'

person.photo = nil # deletes the photo file(s)

FAQs

Package last updated on 10 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts