From e12701b34bcdb4a06bcb65335a5e8b3c7164afde Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 10 Sep 2012 14:19:39 +0800 Subject: [PATCH] preview for association object --- app/models/preview.rb | 10 +++++++++- .../announcement/app/models/bulletin.rb | 8 +++++++- .../built_in_modules/news/app/models/news_bulletin.rb | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/models/preview.rb b/app/models/preview.rb index cbbe1d17..9c55fc79 100644 --- a/app/models/preview.rb +++ b/app/models/preview.rb @@ -10,7 +10,7 @@ class Preview field :object_class_type has_many :preview_files, :autosave => true, :dependent => :destroy - + has_many :preview_associations, :autosave => true, :dependent => :destroy # def object=(params) # save_upload_temp_link(params,"news_bulletin_files_attributes") #unless params[] # self.object_f = params @@ -96,6 +96,14 @@ class Preview eval("virtual_object.#{file.field_name_for_rebuild} = file.file") end end + + preview_associations.each do |local_object| + if local_object.object_in_array + eval("virtual_object.#{local_object.field_name_for_rebuild}.build local_object.object") + else + eval("virtual_object.#{local_object.field_name_for_rebuild} = local_object.object") + end + end virtual_object end diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 69541bc1..7fbd51d8 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -204,7 +204,13 @@ class Bulletin self.bulletin["bulletin_files_attributes"].each_with_index do |atr,idx| preview_object.preview_files.build(:file=>self.bulletin["bulletin_files_attributes"][idx.to_s],:field_name_for_rebuild=>'bulletin_files',:file_in_array=>true) end unless self.bulletin["bulletin_files_attributes"].nil? - preview_object.object = self.bulletin.except("bulletin_files_attributes") + + self.bulletin["bulletin_links_attributes"].each_with_index do |atr,idx| + preview_object.preview_associations.build(:object=>self.bulletin["bulletin_links_attributes"][idx.to_s],:field_name_for_rebuild=>'bulletin_links',:object_in_array=>true) + end unless self.bulletin["bulletin_links_attributes"].nil? + + + preview_object.object = self.bulletin.except("bulletin_files_attributes","bulletin_links_attributes") preview_object end diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb index d7e0f3bb..163705f6 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -246,7 +246,12 @@ class NewsBulletin self.news_bulletin["news_bulletin_files_attributes"].each_with_index do |atr,idx| preview_object.preview_files.build(:file=>self.news_bulletin["news_bulletin_files_attributes"][idx.to_s],:field_name_for_rebuild=>'news_bulletin_files',:file_in_array=>true) end unless self.news_bulletin["news_bulletin_files_attributes"].nil? - preview_object.object = self.news_bulletin.except("news_bulletin_files_attributes","image") + + self.news_bulletin["news_bulletin_links_attributes"].each_with_index do |atr,idx| + preview_object.preview_associations.build(:object=>self.news_bulletin["news_bulletin_links_attributes"][idx.to_s],:field_name_for_rebuild=>'news_bulletin_links',:object_in_array=>true) + end unless self.news_bulletin["news_bulletin_links_attributes"].nil? + + preview_object.object = self.news_bulletin.except("news_bulletin_files_attributes","image","news_bulletin_links_attributes") preview_object end