Skip to content

Instantly share code, notes, and snippets.

@eclubb
Created March 2, 2011 18:03
Show Gist options
  • Save eclubb/851381 to your computer and use it in GitHub Desktop.
Save eclubb/851381 to your computer and use it in GitHub Desktop.
-# Note that in this scenario, there is only one comment.
= simple_form_for @post do |post_form|
...
= post_form.simple_fields_for :comments do |comment_form|
comment_form.input :name
comment_form.input :email
...
-# This should use the same model instance as the fields_for above, but doesn't.
= post_form.simple_fields_for :comments do |comment_form|
comment_form.input :blurb
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
<form method="post" id="edit_post" class="simple_form post" action="/update_post" accept-charset="UTF-8">
...
<div class="input string required">
<label for="post_comments_attributes_0_name" class="string required">
<abbr title="required">*</abbr> Name:
</label>
<input type="text" value="" size="50" required="required" name="post[comments_attributes][0][name]" maxlength="255" id="post_comments_attributes_0_name" class="string required">
</div>
<div class="input string required">
<label for="post_comments_attributes_0_email" class="string required">
<abbr title="required">*</abbr> E-Mail:
</label>
<input type="text" value="" size="50" required="required" name="post[comments_attributes][0][email]" maxlength="255" id="post_comments_attributes_0_email" class="string required">
</div>
...
<!-- This should use post_comments_attributes_0_blurb, not post_comments_attributes_1_blurb. -->
<div class="input string required">
<label for="post_comments_attributes_1_blurb" class="string required">
<abbr title="required">*</abbr> Blurb:
</label>
<input type="text" value="" size="50" required="required" name="post[comments_attributes][1][blurb]" maxlength="255" id="post_comments_attributes_1_blurb" class="string required">
</div>
...
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment