所以,我在“app/views/posts”中的一个名为“_form.html.erb”的部分中有这段代码:
<%= form_for @post do |f| %>
<% if @post.errors.any? %>
<h2>Errores:</h2>
<ul>
<% @post.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %><br />
<br />
<%= f.label :content %><br />
<%= f.text_area :content %>
</p>
我对这段代码有两个看法:
“app/views/posts/new.html.erb”
<h1>Nuevo post</h1>
<%= render 'form' %>
<p>
<%= f.submit "Agregar Nuevo Post" %>
</p>
<% end %>
“app/views/posts/edit.html.erb”
<h1>Editar Post</h1>
<%= render 'form' %>
<p>
<%= f.submit "Actualizar Post" %>
</p>
<% end %>
我想要的是在视图中呈现的表单,但是通过我向您展示的代码,我在服务器中得到了这个错误输出:
SyntaxError in Posts#new
Showing /home/levick/rubyblog/app/views/posts/new.html.erb where line #10 raised:
/home/levick/rubyblog/app/views/posts/new.html.erb:10: syntax error, unexpected keyword_ensure, expecting $end
Extracted source (around line #10):
7: </p>
8: <% end %>
Trace of template inclusion: app/views/posts/new.html.erb
Rails.root: /home/levick/rubyblog
Application Trace | Framework Trace | Full Trace
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None
与编辑视图相同。
我的问题是:我做错了什么?
谢谢!