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