This is a quick little patch to automatically create an assembly for newly-created templates. It seems like a great number of tasks depend on this happening.
-- Matt
--- src/app/models/template.rb | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/app/models/template.rb b/src/app/models/template.rb index 6784354..b8e8804 100644 --- a/src/app/models/template.rb +++ b/src/app/models/template.rb @@ -55,6 +55,8 @@ class Template < ActiveRecord::Base validates_presence_of :platform_version validates_presence_of :architecture
+ after_create :ensure_assembly + def no_instances? unless instances.empty? errors.add(:base, 'There are instances for this template.') @@ -169,4 +171,13 @@ class Template < ActiveRecord::Base xml = obj.body update_from_xml end + + private + + def ensure_assembly + self.assemblies.create!({ + :name => self.name, + :architecture => self.architecture + }) unless self.assemblies.count > 0 + end end
On 04/13/2011 07:51 PM, Matt Wagner wrote:
src/app/models/template.rb | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/app/models/template.rb b/src/app/models/template.rb index 6784354..b8e8804 100644 --- a/src/app/models/template.rb +++ b/src/app/models/template.rb @@ -55,6 +55,8 @@ class Template< ActiveRecord::Base validates_presence_of :platform_version validates_presence_of :architecture
- after_create :ensure_assembly
- def no_instances? unless instances.empty? errors.add(:base, 'There are instances for this template.')
@@ -169,4 +171,13 @@ class Template< ActiveRecord::Base xml = obj.body update_from_xml end
- private
- def ensure_assembly
- self.assemblies.create!({
:name => self.name,
:architecture => self.architecture
- }) unless self.assemblies.count> 0
- end end
Hey Matt,
Nice one. ACK
Thomas
aeolus-devel@lists.fedorahosted.org