2 class LicenseGroup < Peta::Template
4 has_many :resource_pictures
7 validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
8 validates :module_name, :presence => true, :length => {:maximum => 50}
9 validates :caption, :presence => true, :length => {:maximum => 30}
10 validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
19 {:include => {:licenses => {}}}
22 def self.store name, attr
23 #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく
24 lattr = attr["licenses_attributes"]
25 attr.delete "licenses_attributes"
26 #ライセンスグループを先に保存してidを決める
27 r = LicenseGroup.modify_object name, attr
29 #取っておいたライセンスデータとidでライセンス作成
30 if (c = License.stores(lattr, r.id)) > 0
31 r.errors.add :base, License.model_name.human + I18n.t('errors.not_create')
36 def self.import filename
37 LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
40 def self.disp_import_error r
42 puts "json file error. file does not exist or broken"
46 put lg.errors.full_messages