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]>. >> 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. > -- 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]. For more options, visit this group at http://groups.google.com/group/haml?hl=en.
