Skip to content

Instantly share code, notes, and snippets.

@DCarper
Created March 9, 2011 19:28
Show Gist options
  • Save DCarper/862796 to your computer and use it in GitHub Desktop.
Save DCarper/862796 to your computer and use it in GitHub Desktop.
class Album < ActiveRecord::Base
attr_accessible :title
has_one :artist , :dependent => :destroy
has_many :genres , :dependent => :destroy
accepts_nested_attributes_for :artist, :allow_destroy => true
end
class Artist < ActiveRecord::Base
belongs_to :album
def full_name
return self.first_name + ' ' + self.surname
end
end
def new
@album = Album.new
@album.build_artist(:first_name => "garren")
end
<%= form_for @album do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<% f.fields_for :artist do |artist| %>
<p>
<%= artist.label :first_name %><br />
<%= artist.text_field :first_name %>
</p>
<% end %>
<p><%= f.submit %></p>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment