I come a few months late, but I vote for number 3. Using something like "member_class(self.this)" looks nice to me, and avoids a lot of dark magic.
Warm regards, Ignacio El 27-08-2015 a las 23:21, [email protected] escribió: > There is a silent failure to render > that occurs when the value of self.this > is assigned to an Array in a controller index action. > > e.g. This fails to render anything useful: > > def index > a = User.where(active: true).to_a.paginate > self.this = a > hobo_index > end > > (Before you go telling me to just skip calling to_a, understand that > this is simply an example. My own application which is more complex > needs for the list of users to be an array) > > Apparently, a workaround gleaned from an old thread on this > topic from 2011 is to extend the Array with a member_class method > that returns the class of the items in the Array. > > e.g. > > def index > a = User.where(active: true).to_a.paginate > > def a.member_class > first.class rescue nil > end > > self.this = a > hobo_index > end > > While this workaround my index action going again, I don't like the idea > of each Hobo user having to discover > and diagnose this gotcha over and over again. > > I'd like to submit a permanent automatic solution to this problem as a > Hobo PR but first > I'd like to get some opinions on the best strategy. > > Possible strategies I've identified: > 1. Monkey patch Enumerable with member_class > Advantages > * comprehensive > * quick and easy > Disadvantages > * it is widely frowned-upon to monkey patch core modules > * may have unanticipated detrimental side-effects > > 2. Change Hobo::Controller::Model::hobo_index to check if self.this is > an Array that does > not respond to member_class and if so, decorate or extend it with > member_class just > before calling response_block > Advantages > * more limited impact than patching Enumerable > Disadvantages > * does not address any other situations where dryml tags > assume that all valid collections respond_to member_class > > 3. Find all references to member_class in the dryml taglibs and make > each and every one of them check to see > if self.this is an Array and if so, use self.this.first.class > rather than self.this.member_class > Advantages > * does not surprise anyone because no object or class is > being changed or wrapped dynamically > Disadvantages > * a lot more work > * if people define more tags, they may introduce this problem > all over again. > > > Any other suggestions? > > > -- > You received this message because you are subscribed to the Google > Groups "Hobo Users" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at http://groups.google.com/group/hobousers. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/hobousers. For more options, visit https://groups.google.com/d/optout.
