-class LicenseGroup < ActiveRecord::Base
+#ライセンスグループ
+class LicenseGroup < Peta::Template
+ load_manifest
+ has_many :resource_pictures
+ has_many :licenses
+
validates :name, :presence => true, :length => {:maximum => 50}, :uniqueness => true
- validates :classname, :presence => true, :length => {:maximum => 50}
+ validates :module_name, :presence => true, :length => {:maximum => 50}
validates :caption, :presence => true, :length => {:maximum => 30}
- validates :url, :presence => true, :length => {:maximum => 200}, :url => true
+ validates :url, :presence => true, :length => {:maximum => 200}, :url => {:message => I18n.t('errors.messages.url')}
+
+ def supply_default
+ end
+
+ def overwrite
+ end
+
+ def self.show_opt
+ {:include => {:licenses => {}}}
+ end
def self.store name, attr
+ #ライセンスデータがあるとライセンスグループのデータ生成で邪魔するので移しておく
+ lattr = attr["licenses_attributes"]
+ attr.delete "licenses_attributes"
+ #ライセンスグループを先に保存してidを決める
r = LicenseGroup.modify_object name, attr
r.save
+ #取っておいたライセンスデータとidでライセンス作成
+ if (c = License.stores(lattr, r.id)) > 0
+ r.errors.add :base, License.model_name.human + I18n.t('errors.not_create')
+ end
r
end
LicenseGroup.import_file(filename) {|name, attr| LicenseGroup.store(name, attr)}
end
+ def self.disp_import_error r
+ if r == false
+ puts "json file error. file does not exist or broken"
+ else
+ unless r.empty?
+ r.each do |lg|
+ put lg.errors.full_messages
+ end
+ end
+ end
+ end
end