【发布时间】:2011-12-30 17:17:20
【问题描述】:
我有这个form_for:
<%= form_for [post, Comment.new,], :remote => true do |f| %>
<%= f.text_area :content, :cols =>10, :rows => 1%>
<% end %>
<%= f.submit :class => "input_comment" %>
即生成下一段代码html:
<form method="post" id="new_comment" data-remote="true" class="new_comment"
action="/post/4efcda9e1d41c82486000077/comments" accept-charset="UTF-8"><div
style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8">
<input type="hidden" value="ctVfDF/O4FIR91I7bC5MVezQmutOCkX3dcXe73uNPZY=" name="authenticity_token">
<textarea rows="1" name="comment[content]" id="comment_content" cols="10"></textarea>
<input type="submit" value="Create Comment" name="commit" class="input_comment">
</form>
如果我在同一页面中有多个表单,则不是具有相同 id 的 html。
- form_for 生成的 id id="new_comment"
- textarea 的 id 生成 id="comment_content"
在同一个页面中有这么多表单是无效的 html。
如何从 rails 3.1 更改 form_for 方法助手自动生成的 id?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 form-for