2010-09-07 51 views
1

我是新來的ROR ROR新手問題,我按照這個tutorial學習ROR,但是,它顯示在有關的form_for錯誤

<%= 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/> 

那麼,有什麼想法?

回答

4

你有一個錯誤,應該是:

<% form_for .... 

無=

+0

哦,是的~~看來官方教程出了點問題...... – Cheung 2010-09-07 07:20:49

0

使用<% form_for...,而不是<%=

這是因爲在Ruby2 +,<%= form_for..改爲<% form_for..

<%= form_for將工作在紅寶石1.9.3。