Search code examples
ruby-on-railspaperclipactivemodel

How can I use Paperclip gem for Rails in a class that does not inherit from ActiveRecord::Base?


There seems to be some people that have gotten Paperclip working on a regular ruby class by doing something like the following:

require "paperclip"

Class Person
   include Paperclip
   has_attached_file :avatar,{}
end

See here This does not work for me even when using the main Paperclip repo:

$ bundle exec rails c
>> Rails.version
=> "3.1.3"
>> require 'paperclip'
=> false
>> class Monkey
>> include Paperclip
>> has_attached_file :avatar,{}
>> end
NoMethodError: undefined method `has_attached_file' for Monkey:Class

Has anyone gotten this working and can possibly give a clue on what could be going wrong?

Thanks!


Solution

  • Paperclip is pretty explicitly for use with AR.

    Another option is to use carrier wave instead which works pretty well outside AR, with a variety of ORMS, or none:

    https://github.com/jnicklas/carrierwave