Created
September 16, 2011 11:25
-
-
Save durran/1221906 to your computer and use it in GitHub Desktop.
Mongoid with simple form.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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