1

全部,尝试在 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 子句中?

想法在这里?

4

1 回答 1

1
<%= content_tag, :div, post.title, :class => 'my-custom-class' %>

http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag

于 2013-02-17T00:03:46.010 回答