Cheung
Cheung

Reputation: 15552

ROR Newbie question about form_for error

I am new to ROR, i follow this tutorial to learn ROR,however, it show a error on

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

In Aptana Studio, it say :

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

So, any idea?

Upvotes: 1

Views: 1034

Answers (2)

Chakreshwar Sharma
Chakreshwar Sharma

Reputation: 2610

Use <% form_for... instead of <%=

This is because in Ruby2+, <%= form_for.. is changed to <% form_for..

<%= form_for will work on ruby 1.9.3.

Upvotes: 0

jordinl
jordinl

Reputation: 5239

you have an error, should be:

<% form_for ....

Without =

Upvotes: 4

Related Questions