Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

association prints #<Enumerator:0x007fa2e2a9f2e0> #40

Closed
tomchentw opened this Issue · 6 comments

4 participants

@tomchentw

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
      end

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

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 association.map(&method),
ie, [].map(:nil) is called, returning #
so it went wrong.

@carlosantoniodasilva
Collaborator

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
Collaborator

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

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

@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
Collaborator
@carlosantoniodasilva
Collaborator

@nashby :D thanks for the pull request.

@tomchentw

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.