This code works properly (using HAML):
#comments
- @blog.comments.each do |comment|
.comment
.username
- if !eval("comment.user").nil?
#{comment.user.email}
.content
#{comment.content}
However, if I remove the "eval" line i.e.
#comments
- @blog.comments.each do |comment|
.comment
.username
#{comment.user.email}
.content
#{comment.content}
I get an error:
undefined method `email' for nil:NilClass
Even when there are no comments in the database (hence the loop contents should not be evaluated). What is going on?
- if !eval("comment.user").nil?this is ugly, just use- if comment.user