Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
Created September 28, 2011 22:12
Show Gist options
  • Save dakatsuka/1249405 to your computer and use it in GitHub Desktop.
Save dakatsuka/1249405 to your computer and use it in GitHub Desktop.
has_one関連時のaccepts_nested_attributes_for / fields_for
= form_for @user do |f|
= f.fields_for :profile, @user.profile || Profile.new do |p|
.field
= p.label :nickname
= p.text_field :nickname
class Profile < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_one :profile
accepts_nested_attributes_for :profile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment