【发布时间】:2017-06-20 09:03:47
【问题描述】:
我有这段代码用于在一篇文章上显示 cmets,该文章使用 ERB 元素从数据库中获取和显示信息:
<div class="comments">
<h4 class="comment_author">Comment by <%= comment.author_name %></h4>
<p class="comment"><%= comment.body %></p>
</div>
我想以不同的方式格式化 comment.author_name,所以我想在第二行添加一个 id,例如
<h4 class="comment_author">Comment by <%= comment.author_name, id: "commenter" %></h4>
但是,当我这样做时,我得到以下error message。
我过去添加了类和 id 来形成具有 :class=> "name" 语法如下:
<%= f.submit 'Create Article', :class => 'create_new_article_button'%>
但这似乎也不起作用。是否有其他方法可以将 id 和类添加到非表单 ERB 元素?
提前致谢!
【问题讨论】:
-
<h4 class="comment_author", id='commenter''>Comment by <%= comment.author_name %></h4> -
您尝试将
id添加到错误的位置。您目前正尝试在h4的内容中添加id而不是标签本身。
标签: html css ruby-on-rails erb