简体   繁体   中英

How do I disable Attachment Fu Plugin in Community Engine without removing it?

So here is the situation:

The Photo model in Community Engine is using attachment Fu. I, wish to use paperclip instead.

Now this works fine until I have to delete an attachment. That's when the attachment Fu is causing the problem. Here is what Photo.rb looks like (in /vendor/plugins/community_engine/app/models):

class Photo < ActiveRecord::Base


  acts_as_commentable
  belongs_to :album

  has_attachment prepare_options_for_attachment_fu(AppConfig.photo['attachment_fu_options'])

  acts_as_taggable

  acts_as_activity :user, :if => Proc.new{|record| record.parent.nil? && record.album_id.nil?}

  validates_presence_of :size
  validates_presence_of :content_type
  validates_presence_of :filename
  validates_presence_of :user, :if => Proc.new{|record| record.parent.nil? }
  validates_inclusion_of :content_type, :in => attachment_options[:content_type], :message => "is not allowed", :allow_nil => true
  validates_inclusion_of :size, :in => attachment_options[:size], :message => " is too large", :allow_nil => true

...
...

end

So my question is: Is there a way to disable this plugin? I don't want to change photo.rb and delete any lines, nor do I want to remove the plugin.

Any ideas here?

New Photo Model (in /app/):

require 'paperclip_processors/cropper'

class Photo < ActiveRecord::Base   

  attr_accessible :image
  has_attached_file :image,      
                    :path=>":class/:hash/:style.:extension",
                    :styles => {
                      :thumb => {:geometry => "100x100!", :crop_to => :crop_parameters},
                      :medium => {:geometry => "290x320!", :crop_to => :crop_parameters},
                      :large => {:geometry => "664>", :crop_to => :crop_parameters},
                      :uncropped => "630x472"
                    },
                    :convert_options=>'-quality 92',
                    :processors => [:cropper]

  def crop_parameters
    ActiveSupport::JSON.decode(read_attribute(:crop_parameters)) rescue nil
  end


# overrides to make paperclip appear as attachment_fu to existing pages          

  def size # in MB
    image_file_size
  end
  def filename
    image_file_name
  end
  def content_type
    image_content_type
  end


  def public_filename(size=:original)
    image.url(size) || ""
  end

end

New Photo Controller (in /app/):

require 'pp'

class PhotosController < BaseController
  before_filter :use_paperclip, :only => [:create]

  def use_paperclip
    params[:photo][:image] = params[:photo][:uploaded_data]
    params[:photo].delete(:uploaded_data)     
  end

end

If you installed the plugin to your vendor/ directory, then find the plugin under the plugins/ subdirectory and comment out everything in the init.rb . This should disable all functionality of the plugin without removing it from your source tree.

How exactly are you using paperclip, when you haven't initialized anything for it?

You could maybe open up the class in an initializer and change it to meet your needs.

Might be better to add the attachment code using an adapter pattern which is set up from a config file, so you can create a module and include it. This module works out whether to include paperclip or attachement fu depending on some config you create, and where to get the parameters to initialize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM