Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Upload images and videos(vimeo, youtube) and cache using Swfupload and Dragonfly
JavaScript Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
lib
test
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
Rakefile
attachment_magick.gemspec

README.rdoc

Attachment Magick

Attachment Magick is a gem to upload images and videos(vimeo and youtube) using swfupload. Supports Mongoid and ActiveRecord.

Installation

Add to Gemfile

gem 'attachment_magick'

After the gem installation, run the generator

rails g attachment_magick:install

The generator will install swfupload (js and css files) and will create some routes.

And if you are using ActiveRecord, run this too

rails g attachment_magick:migration

Create a initializer like this (config/initializers/attachment_magick_setup.rb)

AttachmentMagick.setup do |config|
  # config.default_add_partial = '/attachment_magick/add_image'  # default

  # You can set grid size manually:
    config.columns_amount = 16
    config.columns_width  = 52
    config.gutter         = 8
  # Or with our magick :)
  # config.parse_stylesheet('name_of_my_grid_file.css')

  config.orms = ["ActiveRecord", "Mongoid"] # Mongoid is default

  config.custom_styles do
    publisher "52x"
    my_custom_style "50x50"
  end
end
  • Attachment Magick is based on 960 Grid System (960.gs/)

Add to application.rb

config.middleware.insert 0, 'Rack::Cache', {
  :verbose     => true,
  :metastore   => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"),
  :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
} # unless Rails.env.production?  ## uncomment this 'unless' in Rails 3.1,
                                  ## because it already inserts Rack::Cache in production

config.middleware.insert_after 'Rack::Cache', 'Dragonfly::Middleware', :images

Getting started

Include the js files to your application layout or page

javascript_include_tag :defaults, "swfupload/handlers", "swfupload/swfupload"

Include AttachmentMagick Module to your model

class Post
  include AttachmentMagick

  attachment_magick
end

Call this helpers in form views

attachment_progress_container @post
attachment_for_view @post
attachment_for_video @post
attachment_for_flash @image.photo.url

For customize your list for images

attachment_for_view @post, 'path/my_partial'

Customizing views

Just Images

<div class="attachment_magick_image" id="image_<%=image.id%>" style="width:inerit; margin-bottom:10px;">
  <%= image_tag image.photo.thumb(image._parent.class.style_publisher).url%>
  <input id ="image_id" type ="hidden" value ="<%=image.id%>">

  <%= link_to "[x]", "javascript://", :class => "remove_image", :style => "float:right;"%>
</div>

<%= attachment_for_view @post, "path_to_my_partial" %>

Customizing sizes

class Post
  include AttachmentMagick

  attachment_magick do
    grid_1 "100x100"
  end
end

Credits

Author: [Marco Singer](github.com/marcosinger) Contributors: [Lucas Renan](github.com/lucasrenan), [Carlos Brando](github.com/carlosbrando)

See in RubyGems.org

(rubygems.org/gems/attachment_magick)

Something went wrong with that request. Please try again.