Paperclip Now a DataMapper Plugin

May 15, 2008 | Reporter: hassox

Ken Robertson aka et-ken on #datamapper has ported the popular Thoughtbot's paperclip rails plugin to Datamapper.

Paperclip a fantastic rails plugins to help with uploading and attaching files to your models is now a DataMapper plugin. You can find it at dm_paperclip

For those who don’t know, Paperclip is a plugin that lets you use files pretty much just like any other attribute.

Code lifted from the README:

Your models just need the has_attched_file attribute. class User include DataMapper::Resource include Paperclip::Resource property :id, Integer, :serial => true property :username, String has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" } end Then in your views: <% form_for @user, { :action => url(:user), :multipart => true } do %> <%= file_field :name => 'avatar' %> <% end %> And in your controller: def create ... @user.avatar = params[:avatar] end

There’s also validations available too. All round a great plugin. Ken has done some great work to get this plugin working with DataMapper 0.9.x and I can’t wait to try it out.

You can checkout Ken’s own writeup at his blog and get the code on Github

Comment On Paperclip Now a DataMapper Plugin

Sign in to make your voice heard