我有一些代码应该检查属性是否存在方法调用,似乎 if 或 else 都没有返回任何东西......
%h2= @post.title
.row
.col-sm-12
= render "blog_meta", :post => @post
#text_body
= @post.content
%hr
- if @post.comments.count > 0
%h2 Comments
#comments
- @post.comments.where(:original_id => nil).each do |comment|
.comment
.profile
%img{:src => "/assets/profile_image_sample.jpg"}
.message
.username
- if comment.user.respond_to?('username')
.username= comment.user.username
- else
.username= comment.user.first_name
= comment.content
- logger.info "LOGGER--->>" + comment.user.first_name
.reply-link
%a{:href => "#"} Reply to Comment
- if comment.replies.count > 0
- nesting = 0
- comment.replies.each do |comment|
= render "comment", :comment => comment, :nesting => nesting
%hr
= render "submit_comment"
但是,如果我只是= comment.user.first_name
没有条件,那么它工作正常..