Skip to content

Instantly share code, notes, and snippets.

@durran
Created September 16, 2011 11:25
Show Gist options
  • Save durran/1221906 to your computer and use it in GitHub Desktop.
Save durran/1221906 to your computer and use it in GitHub Desktop.
Mongoid with simple form.
module SimpleForm
class FormBuilder
alias _find_association_reflectio find_association_reflection
def find_association_reflection(association) #:nodoc:
if reflection = _find_association_reflectio(association)
ActiveModelMetadataProxy.new reflection
end
end
class ActiveModelMetadataProxy
attr_accessor :metadata
def initialize(metadata)
@metadata = metadata
end
def options
metadata
end
def macro
case macro = metadata.macro
when :referenced_in then :belongs_to
when :references_many then :has_many
when :references_and_referenced_in_many then :has_and_belongs_to_many
else macro
end
end
def method_missing(method, *args, &block)
metadata.send(method, *args, &block)
end
end
end
end
@dieb
Copy link

dieb commented Oct 29, 2011

Hello,

I tried putting this file on lib/ for fixing the association problem with mongoid & simple_form but it didn't seem to have any positive result.

What should I do?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment