Hobo / hobo

The web app builder for Rails (moved from tablatom/hobo)
http://hobocentral.net
103 stars 39 forks source link

NoMethodError - undefined method `map!' for #<ActiveRecord::Associations::CollectionProxy []> #177

Closed haslinger closed 8 years ago

haslinger commented 8 years ago

I'm not sure, if this is a bug at all. But it could be useful to document the solution, so I just filed an issue anyways.

The error from the title came up in a dryml-template in the line:

<if test="&this.lineitems">

I learned, that it can be fixed easily by using:

<if test="&this.lineitems.any?">

I'm not sure, if this is a change in Rails's standard behaviour, so I would like to hear a comment from some of you on this.

haslinger commented 8 years ago

Meanwhile a bit more details: The map method is missing in activesupport (4.2.5) lib/active_support/hash_with_indifferent_access.rb line 275. It's a code line from 2013 and I don't get the details, why we haven't been dumping here forever.

The problem only occurs, if the string in the test evals to an ActiveRecord_Relation. The quite similar looking case <repeat with="&this.lineitems"> is still fine, btw.

iox commented 8 years ago

I have reproduced this. There is an error in HashWithIndifferentAccess, when having something a CollectionProxy as a value:

{:test => Foo.first.foobazs}.with_indifferent_access

This is the origin of this strange error. Fortunately, it has been fixed in Rails 5, so the next version of Hobo should have this problem fixed :).

enwood commented 8 years ago

I discovered that forcing the collection to load immediately using .all was my work-around.

See https://groups.google.com/d/topic/hobousers/m5ogxkOcRp0/discussion

Tim