preview for association object

This commit is contained in:
Matthew K. Fu JuYuan 2012-09-10 14:19:39 +08:00
parent 768f907f66
commit e12701b34b
3 changed files with 22 additions and 3 deletions

View File

@ -10,7 +10,7 @@ class Preview
field :object_class_type field :object_class_type
has_many :preview_files, :autosave => true, :dependent => :destroy has_many :preview_files, :autosave => true, :dependent => :destroy
has_many :preview_associations, :autosave => true, :dependent => :destroy
# def object=(params) # def object=(params)
# save_upload_temp_link(params,"news_bulletin_files_attributes") #unless params[] # save_upload_temp_link(params,"news_bulletin_files_attributes") #unless params[]
# self.object_f = params # self.object_f = params
@ -96,6 +96,14 @@ class Preview
eval("virtual_object.#{file.field_name_for_rebuild} = file.file") eval("virtual_object.#{file.field_name_for_rebuild} = file.file")
end end
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 virtual_object
end end

View File

@ -204,7 +204,13 @@ class Bulletin
self.bulletin["bulletin_files_attributes"].each_with_index do |atr,idx| 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) 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? 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 preview_object
end end

View File

@ -246,7 +246,12 @@ class NewsBulletin
self.news_bulletin["news_bulletin_files_attributes"].each_with_index do |atr,idx| 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) 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? 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 preview_object
end end