It sounds to me like perhaps you were destructively modifying the array while you were iterating over it.
Bradley: that is the current behavior. nil attributes aren't rendered. On Thu, Mar 18, 2010 at 12:45 PM, jbrennan <[email protected]> wrote: > Thanks all, got it working. > > Except, when I followed Bradley's instructions, it set the attribute > properly, but it totally mangled the objects I was iterating over. I > have no idea why, some of the content just didn't render, the objects > rendered out of order, etc. I had fetched them from a Datamapper > store. > > Anyway, the problem was fixed by copying the elements of the "@posts" > array into a new array, and iterating over that object instead. I have > no idea what the actual problem is, but it's working perfectly now. > > Thanks again for all the help! > > On Mar 18, 11:02 am, Chris Eppstein <[email protected]> wrote: > > I would love to see that. I thought it might have been part of this > commit: > http://github.com/nex3/haml/commit/782f44f5538b55a81940e042c450f4e8af... > > > > but I guess not. > > > > chris > > > > On Thu, Mar 18, 2010 at 5:29 AM, Bradley Grzesiak <[email protected] > >wrote: > > > > > > > > > You'd have to do something like: > > > %a{:href => post.link, :title => (post == posts.last ? "last post" : > "")} > > > > > With your way, :title was being set to nil, which throws an error. > > > > > Frankly, I see a feature request coming out of this: if an attribute is > set > > > to nil, don't render the attribute. > > > > > Thoughts? > > > > > :brad > > > > > On Thu, Mar 18, 2010 at 12:45 AM, Nathan Weizenbaum <[email protected] > >wrote: > > > > >> Can you post the whole error backtrace? > > > > >> On Wed, Mar 17, 2010 at 8:57 PM, jbrennan <[email protected] > >wrote: > > > > >>> As a simplified example of what I'm trying to do, say I'm displaying > a > > >>> bunch of Posts on a page. My partial would look something like this: > > > > >>> - @posts.each do |post| > > >>> %a{:href => post.link} > > >>> %p= post.body > > > > >>> But what I want to do is set an attribute on the link for the *last* > > >>> post of the page like > > > > >>> - @posts.each do |post| > > >>> %a{:href => post.link, :title => ("last post" if post == > > >>> posts.last)} > > >>> %p= post.body > > > > >>> I've tried the above code but I get an error saying can't compare to > > >>> nilClass, and I'm not sure why either the sender or receiver would be > > >>> nil, as the things I'm rendering show properly (all of them). > > > > >>> Any ideas what I'm doing wrong? > > > > >>> Thanks in advance. > > > > >>> -- > > >>> You received this message because you are subscribed to the Google > Groups > > >>> "Haml" group. > > >>> To post to this group, send email to [email protected]. > > >>> To unsubscribe from this group, send email to > > >>> [email protected]<haml%[email protected]>< > haml%[email protected]<haml%[email protected]> > >. > > >>> For more options, visit this group at > > >>>http://groups.google.com/group/haml?hl=en. > > > > >> -- > > >> You received this message because you are subscribed to the Google > Groups > > >> "Haml" group. > > >> To post to this group, send email to [email protected]. > > >> To unsubscribe from this group, send email to > > >> [email protected]<haml%[email protected]>< > haml%[email protected]<haml%[email protected]> > >. > > >> For more options, visit this group at > > >>http://groups.google.com/group/haml?hl=en. > > > > > -- > > > Bradley Grzesiak > > > co-founder, bendyworks llc > > >http://bendyworks.com/ > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Haml" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<haml%[email protected]>< > haml%[email protected]<haml%[email protected]> > >. > > > For more options, visit this group at > > >http://groups.google.com/group/haml?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Haml" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected] <haml%[email protected]>. > For more options, visit this group at > http://groups.google.com/group/haml?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Haml" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/haml?hl=en.
