我具有用于显示在其上使用ERB元件获取并从数据库中显示的信息的文章评论此代码:如何包含在一个ERB元件的ID(或类)
<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。
我在过去加class和id以形成与 元素:类=>“名”的语法像这样:
<%= f.submit 'Create Article', :class => 'create_new_article_button'%>
但是,这似乎并没有任何在这里工作。有没有不同的方法可以将IDS和类添加到非表单ERB元素中?
提前致谢!
'
评论来自<%= comment。author_name%>
' –您试图在错误的地方添加'id'。您目前正试图在标签本身的'h4'&NOT内容中添加'id'。 –