有人可以告诉我这里我做错了什么吗?当我尝试加载表单(/ 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 %>
以下是相关代码:
文章/ SHOW
<%= 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 %>
答案 0 :(得分:1)
您正在尝试将form_tag_remote
与块一起使用:
<%= form_remote_tag ... %>
...
<% end %>
但你遗漏了do
来开始阻止。您的ERB看起来应该更像这样:
<%= form_remote_tag(...) do %>
<!-- ----------------^^ -->
<% end %>
ERB处理器实质上将ERB源内部转换为生成一串Ruby代码来执行;额外的步骤可能导致一些非常奇怪的错误,难以追查。从ERB到Ruby的部分转换涉及一些异常处理,因此令人困惑和奇怪的看起来
unexpected kENSURE, expecting $end
在错误消息中。