form_for 关闭
我的页面上发生了一种奇怪的情况,我的
这是基本的 ERB:
<%= form_for(@review) do |f| %>
<%= render 'apply/review_form', :locals => {:f => f} %>
<%= f.text_field :notes %>
<% end %>
看起来很简单,对吧?我已经尝试过单独的部分; text_field
本身;使用 form_tag
的不同版本,但没有任何效果。
HTML 看起来像这样:
<div id="reviewContainer">
<form accept-charset="UTF-8" action="/reviews" class="new_review" id="new_review" method="post">
</form>
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" value="dJSuLMfhBSVKAM3Buwe1NjtBedSLQl062/+oliGbBfE=">
</div>
<input id="review_notes" name="review[notes]" size="30" type="text">
<div class="clear"></div>
</div>
有什么想法吗?这看起来很简单,我不明白为什么它不起作用!
可能有用的信息
此表单不是页面上的唯一表单,它包含在 JQuery Tools Scrollable 中。
I have a strange situation happening on a page where my <form>
tags are being closed immediately, leaving the form's contents on their own and not useful.
Here's the basic ERB:
<%= form_for(@review) do |f| %>
<%= render 'apply/review_form', :locals => {:f => f} %>
<%= f.text_field :notes %>
<% end %>
Seems simple, right? I have tried the partial on its own; the text_field
on its own; a different version using form_tag
, but nothing works.
The HTML looks like this:
<div id="reviewContainer">
<form accept-charset="UTF-8" action="/reviews" class="new_review" id="new_review" method="post">
</form>
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" value="dJSuLMfhBSVKAM3Buwe1NjtBedSLQl062/+oliGbBfE=">
</div>
<input id="review_notes" name="review[notes]" size="30" type="text">
<div class="clear"></div>
</div>
Any ideas? It seems so simple I can't understand why it wouldn't be working!
Possibly helpful information
This form is not the only form on the page, and it is enclosed in a JQuery Tools Scrollable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了这个问题并解决了。对我来说,这是因为我在无效的地方渲染了表单。具体来说,我有一些这样的内容:
将隐藏的 div(及其内部的表单)移动到标签中修复了问题。
I had this problem and figured it out. For me, it was because I was rendering the form in an invalid place. Specifically, I had some content like this:
Moving the hidden div (and the form inside it) into the tag fixed the problem.
您使用什么版本的 Rails?因为直到 2.3.2 form_for 都没有返回值,
请注意开头缺少“=”!
What version of Rails are you using? Coz till 2.3.2 form_for didn't return back a value
Note the "=" missing at the start!
我的解决方法是在结束之前添加提交按钮并使该按钮不显示。
这将结束标签放在我需要的地方。
My way to fix it is to include the submit button right before the end and make the button not display.
This puts the ending tag right where I need it.