![](/img/trans.png)
[英]syntax error, unexpected ',', expecting tCOLON2 or '[' or '.' when assigning a class to erb
[英]Assigning a class in a .erb clause, “syntax error, unexpected tASSOC, expecting tCOLON2”
全部,嘗試在erb文件中分配類時遇到以下語法錯誤:
SyntaxError in Posts#index
Showing [..]/app/views/posts/_post.html.erb where line #5 raised:
[..]/app/views/posts/_post.html.erb:5: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
...append= ( post.title, :class => 'my-custom-class' );@output_...
...
^
3: <td>
4: <div>
5: <%= post.title, :class => 'my-custom-class' %>
6: </div>
7: </td>
我可以將類添加到<div>
-即<div class='my-custom-class'> .. </div>
,但是沒有div,沒有更優雅的方法將類分配嵌入到erb子句?
這里有想法嗎?
<%= content_tag, :div, post.title, :class => 'my-custom-class' %>
http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.