【发布时间】:2015-04-12 03:57:56
【问题描述】:
我正在使用可评论的 gem,我想在留下评论时发送通知电子邮件 - 取决于记录的类型。
def send_comment_notification_email
klass = Object.const_get commentable_type
resource = klass.find_by(id: commentable_id)
if parent_id.nil?
if commentable_type == "Review"
# CommentMailer.new_review_comment(resource, self).deliver
elsif commentable_type == "Movie"
if !resource.company_id.nil?
CommentMailer.new_company_stack_comment(resource, self).deliver
end
if resource.owner_type == 'User'
CommentMailer.new_personal_stack_comment(resource, self).deliver
end
elsif commentable_type == "MovieItem"
unless resource.stack.owner.nil?
# CommentMailer.new_stack_item_comment(resource, self).deliver
end
end
end
end
为什么会出错:
SyntaxError - 语法错误,意外的输入结束,期待关键字结束:
我不能嵌套这样的 if 语句吗?
【问题讨论】:
-
这部分代码没有语法问题。语法错误必须在文件的另一部分。
-
您介意更准确地说
end是什么导致问题吗? -
您可以发布堆栈跟踪以了解哪一行导致问题吗?您的代码看起来不错,因此堆栈跟踪会有所帮助。
标签: ruby-on-rails ruby if-statement