Skip to content

Instantly share code, notes, and snippets.

@justinfrench
Created October 20, 2009 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfrench/214637 to your computer and use it in GitHub Desktop.
Save justinfrench/214637 to your computer and use it in GitHub Desktop.
# renders a post[author_attributes][login]
form_for(@new_post) do |post|
post.fields_for(:author) do |author|
concat(author.text_field(:login))
end
end
# renders a post[author][login]
form_for(@new_post) do |post|
post.fields_for(@new_post.author) do |author|
concat(author.text_field(:login))
end
end
# renders a post[author_attributes][login]
semantic_form_for(@new_post) do |post|
post.semantic_fields_for(:author) do |author|
concat(author.text_field(:login))
end
end
# renders a post[author_attributes][login]
semantic_form_for(@new_post) do |post|
post.inputs :for => :author do |author|
concat(author.input(:login))
end
end
# renders a post[author_attributes][login]
semantic_form_for(@new_post) do |post|
post.inputs :for => [:author, @new_post.author] do |author|
concat(author.input(:login))
end
end
# renders a post[author][login]
semantic_form_for(@new_post) do |post|
post.inputs :for => @new_post.author do |author|
concat(author.input(:login))
end
end
output_buffer.should have_tag("form input[@name='post[author_attributes][login]']", :count => 4)
output_buffer.should have_tag("form input[@name='post[author][login]']", :count => 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment