@@ -30,7 +30,9 @@ class Material < ApplicationRecord
3030 text :description
3131 text :contact
3232 text :doi
33- text :authors
33+ text :authors do
34+ authors . map ( &:full_name )
35+ end
3436 text :contributors
3537 text :target_audience
3638 text :keywords
@@ -51,7 +53,9 @@ class Material < ApplicationRecord
5153 end
5254 # other fields
5355 string :title
54- string :authors , multiple : true
56+ string :authors , multiple : true do
57+ authors . map ( &:full_name )
58+ end
5559 string :scientific_topics , multiple : true do
5660 scientific_topics_and_synonyms
5761 end
@@ -102,6 +106,10 @@ class Material < ApplicationRecord
102106
103107 has_many :stars , as : :resource , dependent : :destroy
104108
109+ has_many :material_authors , dependent : :destroy
110+ has_many :authors , through : :material_authors
111+ accepts_nested_attributes_for :authors , allow_destroy : true , reject_if : :all_blank
112+
105113 # Remove trailing and squeezes (:squish option) white spaces inside the string (before_validation):
106114 # e.g. "James Bond " => "James Bond"
107115 auto_strip_attributes :title , :description , :url , squish : false
@@ -111,10 +119,10 @@ class Material < ApplicationRecord
111119 validates :other_types , presence : true , if : proc { |m | m . resource_type . include? ( 'other' ) }
112120 validates :keywords , length : { maximum : 20 }
113121
114- clean_array_fields ( :keywords , :fields , :contributors , :authors ,
122+ clean_array_fields ( :keywords , :fields , :contributors ,
115123 :target_audience , :resource_type , :subsets )
116124
117- update_suggestions ( :keywords , :contributors , :authors , : target_audience,
125+ update_suggestions ( :keywords , :contributors , :target_audience ,
118126 :resource_type )
119127
120128 def description = ( desc )
@@ -212,7 +220,7 @@ def to_oai_dc
212220 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd' ) do
213221 xml . tag! ( 'dc:title' , title )
214222 xml . tag! ( 'dc:description' , description )
215- authors . each { |a | xml . tag! ( 'dc:creator' , a ) }
223+ authors . each { |a | xml . tag! ( 'dc:creator' , a . full_name ) }
216224 contributors . each { |a | xml . tag! ( 'dc:contributor' , a ) }
217225 xml . tag! ( 'dc:publisher' , content_provider . title ) if content_provider
218226
0 commit comments