Tôi có form_for này:Thay đổi hình thức html id được tạo ra bởi form_for ray 3.1
<%= form_for [post, Comment.new,], :remote => true do |f| %>
<%= f.text_area :content, :cols =>10, :rows => 1%>
<% end %>
<%= f.submit :class => "input_comment" %>
Đó tạo mã html tiếp theo:
<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>
Nếu tôi có nhiều hình thức trong một trang tương tự không phải là một html hợp lệ với cùng một id.
- Các id cho form_for tạo id = "new_comment"
- Các id cho textarea tạo id = "COMMENT_CONTENT"
Với rất nhiều hình thức trong một trang tương tự không hợp lệ html.
Làm thế nào tôi có thể thay đổi AutoGenerate id bởi form_for phương pháp helper từ đường ray 3.1?
Cách hoạt động cho id vùng văn bản? id = "comment_content"? Cảm ơn – hyperrjas
Đối với khu vực văn bản hoặc nút, trường ... v.v ... ví dụ như ': id =>" text _ # {post.id} "'. – hyperrjas
Bạn sẽ làm điều tương tự, nhưng với một 'text_area' nó unecessarry để vượt qua nó trong vòng': html => {} '. Như trong '<% = f.text_area: nội dung,: cols => 10,: rows => 1,: id => "comment_on _ # {} post.id _content" %>'. Kiểm tra các tài liệu cho các [text_area hình thức helper] (http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_area) cho đường ray. – Batkins