Skip to content

association prints #<Enumerator:0x007fa2e2a9f2e0> #40

tomchentw opened this Issue May 22, 2012 · 6 comments

4 participants


Hi everyone,
I'm appreciated all of u for creating such a great work. However, there's a bug in
"/lib/show_for/association.rb" HERE

starting with line 40,

def values_from_association(association, options) #:nodoc:
      sample = association.is_a?(Array) ? association.first : association

      if options[:method]
        options[:using] = options.delete(:method)
        ActiveSupport::Deprecation.warn ":method is deprecated. Please use :using instead", caller

      method = options.delete(:using) || ShowFor.association_methods.find { |m| sample.respond_to?(m) }
      association.is_a?(Array) ? : association.try(method)

lets assume association = [], so sample = is NIL!!!!
in line 48, if no :using is provided, then ShowFor.association_methods.find would return nil due to sample == nil
We get method == nil, then next line, we call,
ie, [].map(:nil) is called, returning #
so it went wrong.


Are you getting an error or it's just the output? This works because it'll never call :nil due to the empty array:

>> [].map &:nil
=> []

Please post your entire show_for code, exactly how it is on your view, and the entire output as well. Thanks.

nashby commented May 22, 2012

@carlosantoniodasilva I think @tomchentw means that method is nil (not a Symbol) so:

> [].map &nil
 => #<Enumerator: []:map>

@nashby wrong Carlos ;). Hehe ok, I missed the final part, thanks for claryfing.

I don't have time to look into this anytime soon, so if anyone wants to try out a pull request, would be more than welcome. Thanks!


@nashby :D thanks for the pull request.


Thanks you all :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.