diff --git a/attachinary.gemspec b/attachinary.gemspec index 8a8d8806..1b1272db 100644 --- a/attachinary.gemspec +++ b/attachinary.gemspec @@ -16,8 +16,8 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib,vendor}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] s.test_files = Dir["test/**/*"] - s.add_dependency 'rails', '>= 3.2' - s.add_dependency 'cloudinary', '~> 1.1.0' + s.add_dependency 'rails', '>= 3.2', '< 5.2' + s.add_dependency 'cloudinary', '~> 1.8' s.add_development_dependency 'sqlite3' s.add_development_dependency 'rspec-rails' diff --git a/lib/attachinary/orm/active_record/extension.rb b/lib/attachinary/orm/active_record/extension.rb index 05946bfc..e8b400ce 100644 --- a/lib/attachinary/orm/active_record/extension.rb +++ b/lib/attachinary/orm/active_record/extension.rb @@ -15,10 +15,17 @@ def attachinary_orm_definition(options) class_name: '::Attachinary::File', conditions: { scope: options[:scope].to_s }, dependent: :destroy + elsif Rails::VERSION::MAJOR > 3 && Rails::VERSION::MAJOR < 5 + has_many :"#{relation}", + -> { where scope: options[:scope].to_s }, + as: :attachinariable, + class_name: '::Attachinary::File', + dependent: :destroy else has_many :"#{relation}", -> { where scope: options[:scope].to_s }, as: :attachinariable, + inverse_of: :attachinariable, class_name: '::Attachinary::File', dependent: :destroy end