Created
March 9, 2011 19:28
-
-
Save DCarper/862796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Artist < ActiveRecord::Base | |
| belongs_to :album | |
| def full_name | |
| return self.first_name + ' ' + self.surname | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def new | |
| @album = Album.new | |
| @album.build_artist(:first_name => "garren") | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= 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