Rails-7 ArgumentError Unknown key: :on. Valid keys are: :if, :unless, :prepend | mongoid-paperclip

132 Views Asked by At

I am a beginner I am trying to migrate Rails 4 to rails 7.0.6 for upload image i used mongoid-paperclip

gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git', branch: 'master'
gem 'mongoid-paperclip', require: 'mongoid_paperclip'

IN Model

has_mongoid_attached_file :image,
                            :path => ":rails_root/public/uploads/images/:organization_id/meals/:id/:style.:extension",
                            :url => "/uploads/meals/:id/:style.:extension",
                            :styles => {
                                :small => ['100x100', :png],
                                :app_show_display  => ['768x431#', :png],
                            }
  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"], :message => "You should select the right format"
  can_attach_from_remote_url :image

after updating with the if conditions, still i am facing the issue .

has_mongoid_attached_file :image,
                            :if => :attach_file_condition
                            :path => ":rails_root/public/uploads/images/:organization_id/meals/:id/:style.:extension",
                            :url => "/uploads/meals/:id/:style.:extension",
                            :styles => {
                                :small => ['100x100', :png],
                                :app_show_display  => ['768x431#', :png],
                            }
  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"], :message => "You should select the right format"
  can_attach_from_remote_url :image

def attach_file_condition
    if !org.id.nil?
        true
      else
        false
      end
  end

0

There are 0 best solutions below