0

有人可以告诉我我在这里做错了什么吗?当我尝试加载表单 (/posts/show) 时出现以下错误:

SyntaxError in Posts#show

Showing /Users/fkhalid2008/loand/app/views/posts/show.html.erb where line #10 raised:

compile error
/Users/fkhalid2008/loand/app/views/posts/show.html.erb:10: syntax error, unexpected kENSURE, expecting $end
Extracted source (around line #10):

7: </div>
8:   <button type="submit" class="btn span6 large">Submit</button>
9: <% end %>

以下是相关代码:

帖子/节目

<%= form_remote_tag( :update => 'message', :url => {:controller => 'main', :action => 'send_message', :user_id => @post.user.id }) %> 
<br>
<br />
<br />
<div class="field">
Hello! My name is <%= f.text_field :subject %> and I'm contacting you in response to your ad. I'm interested in learning more so get in touch! Here's my contact details: <%= f.text_field :body %>.
</div>
<button type="submit" class="btn span6 large">Submit</button>
<% end %>
4

1 回答 1

1

您正在尝试使用form_tag_remote块:

<%= form_remote_tag ... %>
    ...
<% end %>

但是您忽略了do启动块。你的 ERB 应该看起来更像这样:

<%= form_remote_tag(...) do %> 
    <!-- ----------------^^ -->
<% end %>

ERB 处理器本质上是把 ERB 源从里到外转换成一个 Ruby 代码块来执行;这个额外的步骤可能会导致一些非常奇怪的错误,这些错误很难追踪。从 ERB 到 Ruby 的部分转换涉及一些异常处理,因此看起来令人困惑和奇怪

unexpected kENSURE, expecting $end

在错误消息中。

于 2012-04-22T20:44:40.497 回答