我有以下行,其中包含在视图中使用 RoR 的正则表达式(show.html.haml):
- unless @article.content =~ /find(#{image.id})/
问题是正则表达式没有被评估,因为它被解释为注释。我怎样才能逃避评论?
Find centralized, trusted content and collaborate around the technologies you use most.
Learn moreTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more我有以下行,其中包含在视图中使用 RoR 的正则表达式(show.html.haml):
- unless @article.content =~ /find(#{image.id})/
问题是正则表达式没有被评估,因为它被解释为注释。我怎样才能逃避评论?
- unless @article.content =~ Regexp.new("find(#{image.id})")
或者
- unless @article.content =~ %r{find(#{image.id})}
编辑:我想我并没有真正回答这个问题。要逃避评论,请查看cyle建议使用该\
角色的答案。