Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add an ':association_options' option for passing additional options t…

…o the association creation methods.

Signed-off-by: rick <technoweenie@gmail.com>
  • Loading branch information...
commit 45b0e31c895f9f752359116c497c65d44ec16cbc 1 parent 2c164b6
@FooBarWidget FooBarWidget authored technoweenie committed
Showing with 6 additions and 1 deletion.
  1. +1 −0  README
  2. +5 −1 lib/technoweenie/attachment_fu.rb
View
1  README
@@ -50,6 +50,7 @@ has_attachment(options = {})
:processor # Sets the image processor to use for resizing of the attached image.
# Options include ImageScience, Rmagick, and MiniMagick. Default is whatever is installed.
:uuid_primary_key # If your model's primary key is a 128-bit UUID in hexadecimal format, then set this to true.
+ :association_options # attachment_fu automatically defines associations with thumbnails with has_many and belongs_to. If there are any additional options that you want to pass to these methods, then specify them here.
Examples:
View
6 lib/technoweenie/attachment_fu.rb
@@ -103,7 +103,11 @@ def has_attachment(options = {})
end
attachment_options[:path_prefix] = attachment_options[:path_prefix][1..-1] if options[:path_prefix].first == '/'
- with_options :foreign_key => 'parent_id' do |m|
+ association_options = { :foreign_key => 'parent_id' }
+ if attachment_options[:association_options]
+ association_options.merge!(attachment_options[:association_options])
+ end
+ with_options(association_options) do |m|
m.has_many :thumbnails, :class_name => "::#{attachment_options[:thumbnail_class]}"
m.belongs_to :parent, :class_name => "::#{base_class}" unless options[:thumbnails].empty?
end
Please sign in to comment.
Something went wrong with that request. Please try again.