Wrapping Rails ActiveSupport::Concern into other Concerns

162 views Asked by At

I have created a ActiveSupport::Concern, and inside a ClassMethods method I'm calling the mount_uploader method from Carrierwave

/lib/my_concern.rb

require 'active_support/concern'

module MyConcern
  extend ActiveSupport::Concern 

  included do
  end 

  module ClassMethods
    def cover_image
      attr_accessible :cover_image
      mount_uploader :cover_image, "CoverImageUploader"
    end
end

ActiveRecord::Base.send(:include, MyConcern)

/app/models/my_model.rb

class MyModel < ActiveRecord::Base  
  cover_image
end

It all works well until I change something (I mean anything) in the class that I called the method, then I gives me:

undefined method `cover_image_url' for #<MyModel:0x007fa0b043dbb0>

I believe is something related in how it loads those methods.

Ps: I'm using Thin in my dev enviroment, and every time that gives me the error and I restart the server it come back to work.

0

There are 0 answers