我是ROR的新手,我按照tutorial来学习ROR,但是,它显示错误
<%= form_for([@post, @post.comments.build]) do |f| %>
<%= f.error_messages %>
<div class="field">
<%= f.label :commenter %>
<br/>
<%= f.text_field :commenter %>
</div>
<div class="field">
<%= f.label :body %>
<br/>
<%= f.text_area :body %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
在Aptana Studio中,它说:
ActionView::TemplateError (compile error
/home/ming/new/app/views/posts/show.html.erb:31: syntax error, unexpected ')'
...post.comments.build]) do |f| ).to_s); @output_buffer.concat(...
^
/home/ming/new/app/views/posts/show.html.erb:51: syntax error, unexpected kENSURE, expecting ')'
/home/ming/new/app/views/posts/show.html.erb:53: syntax error, unexpected kEND, expecting ')') on line #31 of app/views/posts/show.html.erb:
28: <% end %>
29:
30: <h2>Add a comment:</h2>
31: <%= form_for([@post, @post.comments.build]) do |f| %><%= f.error_messages %>
32: <div class="field">
33: <%= f.label :commenter %>
34: <br/>
那么,任何想法?
答案 0 :(得分:4)
你有错误,应该是:
<% form_for ....
没有=
答案 1 :(得分:0)
使用<% form_for...
代替<%=
这是因为在Ruby2 +中,<%= form_for..
更改为<% form_for..
<%= form_for
将适用于ruby 1.9.3。