Skip to content

Commit

Permalink
Add an ':association_options' option for passing additional options t…
Browse files Browse the repository at this point in the history
…o the association creation methods.

Signed-off-by: rick <technoweenie@gmail.com>
  • Loading branch information
FooBarWidget authored and technoweenie committed Feb 13, 2009
1 parent 2c164b6 commit 45b0e31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions README
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion lib/technoweenie/attachment_fu.rb
Expand Up @@ -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
Expand Down

0 comments on commit 45b0e31

Please sign in to comment.