我具有用於顯示在其上使用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'。 –