在.erb子句中分配一个类,“语法错误,意外的tASSOC,期待tCOLON2”

时间:2013-02-16 23:52:49

标签: ruby-on-rails

全部,我在尝试在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子句中嵌入类赋值?

这里的想法?

1 个答案:

答案 0 :(得分:1)

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

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