Created
December 15, 2011 22:49
-
-
Save abuisman/1483326 to your computer and use it in GitHub Desktop.
Problem with :name of child
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
module AssetChild | |
# by defining a module this should allow us to make nice code which adds: | |
# | |
# - has_one :assets | |
# - adds an after_create hook which automaticly builds the asset. | |
# - at some latter point we can also add after_update - to update the asset it's timestamp. | |
# - give access to asset attributes such as name => @usecase.name instead of @usecase.asset.name | |
# | |
# -> http://weblog.jamisbuck.org/2007/1/17/concerns-in-activerecord | |
def self.included(base) | |
base.has_one :asset, :as => :assetchild | |
base.has_one :project, :through => :asset | |
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
class Actor < ActiveRecord::Base | |
# Is asset child | |
include AssetChild | |
accepts_nested_attributes_for :asset | |
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 Asset < ActiveRecord::Base | |
belongs_to :assetchild, :polymorphic => true | |
accepts_nested_attributes_for :assetchild | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment